JCarnac3D-OGL provides a dedicated rendering node to display point sets with properties : cgJOGL3DBiAttributePointSetNode
This node is able to handle 4 properties that each link to one of the following rendering parameters :
point size
point color
symbol type (from a symbol map)
transparency.
Note : the node name has not been modified even if its capabilities have been increased.
The following sample fully initializes a point set with a property mapped to the point color and a property mapped to the point size.
Sample code
// Number of coordinates and the coordinates int npts = 4; double[] xcoords = new double[] { 75, 60, 2, 30 }; double[] ycoords = new double[] { 43, 64, 80, 5 }; double[] zcoords = new double[] { 71, 89, 71, 61 }; // ConstructorcgJOGL3DBiAttributePointSetNode pointSet = new cgJOGL3DBiAttributePointSetNode( xcoords, ycoords, zcoords, npts);
Result :
Setting the point color attribute
Sample code
// Color values array and settings (bounds are [0, 100]) double[] colorValues = new double[] { 99, 40, 80, 5 }; double minColorValue = 0.; double maxColorValue = 100.; // Color map Color[] colorMap = new Color[] { Color.BLUE, Color.GREEN, Color.RED }; // ConstructorcgJOGL3DBiAttributePointSetNode pointSet = new cgJOGL3DBiAttributePointSetNode( xcoords, ycoords, zcoords, npts);
//set color values and color map pointSet.setColorMap(colorMap); pointSet.setAttribute(PointAttribute.COLOR, colorValues); pointSet.setAttributeRange(PointAttribute.COLOR, minColorValue, maxColorValue);
//Explicitly tells the node to use a color map instead of the default color.
pointSet.setDefaultStateUse(PointAttribute.COLOR, false);
Setting the point size attribute
Sample code
// Size values array and settings (bounds are [-100, 100]) double[] sizeValues = new double[] { -52, 90, 1, -35 }; double minSizeValue = -100.; double maxSizeValue = 100.; // Bounds of the points size double pointSizeMin = 5.; double pointSizeMax = 50.; // ConstructorcgJOGL3DBiAttributePointSetNode pointSet = new cgJOGL3DBiAttributePointSetNode( xcoords, ycoords, zcoords, npts); //set size values pointSet.setAttribute(PointAttribute.SIZE, sizeValues); pointSet.setAttributeRange(PointAttribute.SIZE, minSizeValue, maxSizeValue);
//explicitly tells the node to use a point size attribute instead of the default size
pointSet.setDefaultStateUse(PointAttribute.SIZE, false); //sets the minimum and maximum size of a symbol (in pixels) pointSet.setPointSizeRange(pointSizeMin, pointSizeMax);
Setting the point symbol attribute
Sample code
// Size values array and settings (bounds are [-100, 100]) double[] sizeValues = new double[] { -52, 90, 1, -35 }; double minSizeValue = -100.; double maxSizeValue = 100.;
cgJOGL3DBiAttributePointSetNode pointSet = new cgJOGL3DBiAttributePointSetNode( xcoords, ycoords, zcoords, npts); //set symbol values pointSet.setAttribute(PointAttribute.SYMBOL, sizeValues); pointSet.setAttributeRange(PointAttribute.SYMBOL, minSizeValue, maxSizeValue); //create a symbol map cgSymbolMap map = new cgSymbolMap(); map.setSymbol(0, "plus"); map.setSymbol(1, "circle"); map.setSymbol(2, "triangle"); //set the symbol map pointSet.setSymbolMap(map); //explicitly tells the node to use a symbol map instead of the default symbol. pointSet.setDefaultStateUse(PointAttribute.SYMBOL, false); pointSet.setSymbolOrientation(true);//true to face camera, false otherwise.
The possible symbol names are :
Cross
Circle
Star
Plus
Square
Diamond
Triangle
Setting the point transparency attribute
Sample code
// transparency values array and settings (bounds are [-100, 100]) double[] trValues = new double[] { -52, 90, 1, -35 }; double minTrValue = -52.; double maxTrValue = 90.; // ConstructorcgJOGL3DBiAttributePointSetNode pointSet = new cgJOGL3DBiAttributePointSetNode( xcoords, ycoords, zcoords, npts); //set transparency values pointSet.setAttribute(PointAttribute.TRANSPARENCY, trValues); pointSet.setAttributeRange(PointAttribute.TRANSPARENCY, minTrValue, maxTrValue);
//explicitly tells the node to use a point transparency attribute instead of the default size
pointSet.setDefaultStateUse(PointAttribute.TRANSPARENCY, false);
Result (without transparency setting) :