Skip to main content

Problem with PointArray.getCoordinates and getColors function

2 replies [Last post]
Joined: 2010-08-22

I m using binary build version 1.5.2

What i found that this piece of code don't work for me

<br />
Color3b[] colour=new Color3b(count);      //count is integer of value 9000<br />
Point3f[] pointCoord=new Point3f(count);<br />
PointArray lastSet= new PointArray( count, GeometryArray.COLOR_3 | GeometryArray.COORDINATES );    //new PointArray to copy the data from a PointArray</p>
<p>pointArray.getColors(0, colour);                          //PointArray object, mine have 10000 3D points in float<br />
pointArray.getCoordinates(0, pointCoord);</p>
<p>lastSet.setCoordinates(0,pointCoord);<br />
lastSet.setColors(0, colour);</p>
<p>objTrans.addChild(new Shape3D(lastSet,new Appearance()));<br />


Its giving nullpointerrefernce exception for both getCoordinates and getColors but if i do this in this manner it works for my objective
Color3b colour=new Color3b();
Point3f pointCoord=new Point3f();
PointArray lastSet= new PointArray( count, GeometryArray.COLOR_3 | GeometryArray.COORDINATES );

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-06-18


the reason is quite simple: You have to initialize the arrays you are copying into with new objects, because the methods don't put the original color/point objects in it but just store the values.

Thus something like this works:

private BranchGroup test(){
PointArray pointArray = new PointArray(10000,GeometryArray.COLOR_3| GeometryArray.COORDINATES);
for (int i=0;i<10000;i++){
pointArray.setCoordinate(i,new Point3d());
pointArray.setColor(i, new Color3b());

Color3b[] colour=new Color3b[9000];
for (int i=0;i<9000;i++)
colour[i]=new Color3b();
Point3f[] pointCoord=new Point3f[9000];
for (int i=0;i<9000;i++)
pointCoord[i]=new Point3f();
PointArray lastSet= new PointArray( 9000, GeometryArray.COLOR_3 | GeometryArray.COORDINATES );

pointArray.getColors(0, colour);
pointArray.getCoordinates(0, pointCoord);

lastSet.setColors(0, colour);

BranchGroup objTrans = new BranchGroup();
objTrans.addChild(new Shape3D(lastSet,new Appearance()));

return objTrans;

Btw. use code tags to include code in the message. Then you can post correct brackets and the code wouldn't look broken ;)


fixed code part to display correctly

Message was edited by: mulchi

Joined: 2010-08-22

Thanx for clearing my doubt