Skip to main content

about updateData

6 replies [Last post]
code`poet
Offline
Joined: 2006-02-17

Hi everyone.

I have many geometries. From the main class I call UpdateMyGeom(wihtout .updateData(this) and the equivalent of CreateMyGeom) and it updates geoms with the new data. Method "updateData(Geometry geometry)" is empty.

Result: it updates the last geometry only... why it updates anything at all?? How this mechanism works?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kcr
Offline
Joined: 2004-03-17

It is not legal to modify "by-reference" geometry data outside of a GeometryUpdater that is called from the updateData method of that geometry. If you do this, this results are unspecified -- all bets are off.

-- Kevin

code`poet
Offline
Joined: 2006-02-17

ok.
And the main question. I have method UpdateMyData, where I use external data from another class. But updateData(Goemetry geom) do not apply external input values, so what is the best way(performance and memory) to send external data to updater. For clearness:

public void UpdateMyData(float[] a, float[][] b){
for(i...){
// calculations
((GeometryArray)trianglearray[i]).update(this);
}
}

public void updateData(Geometry geometry) {
//here i have to do calculations, but not in UpdateMyData
//and what else must be here for updating?
}

I think, that as a solution is: make a new method GetExternalData and new visible variables and equate extra data to internal(where updateData is located); so it will be possible use external data for calculations in updateData(Geometry geom). But bad for memory :(

kcr
Offline
Joined: 2004-03-17

> for(i...){
> // calculations
> ((GeometryArray)trianglearray).update(this);
> }

What is "i" looping over? If you are calling update multiple times for a single geometry (e.g., for each point), you will want to rethink your approach, as this will perform very badly. Perhaps pushing some of the computation into the updateData method would help. In any case, the following pattern might be useful to you:

[code]
public void updateMyData(float[] a, float[][] b) {
final float[] tmpA = a;
final float[][] tmpB = b;
trianglearray.updateData(new GeometryUpdater() {
public void updateData(Geometry geometry) {
// use tmpA and tmpB to compute new data...
}
});
}
[/code]

-- Kevin

code`poet
Offline
Joined: 2006-02-17

Danke! This pattern is very usefull for me... but the result is not the same as the understanding of this... may be because of I use Xith3D, which seems to be very similar to Java3D.

So, I call method:
[i]...
for(int s =0; s view.renderOnce();
...[/i]

The body of method is:

[i]public void UpdateMyData(int getSurface, int[] getCoordsFace,int[][][] faces) {

System.out.println("Updating data...");

final int TMPsurff/*getSurface*/ = getSurface;
final int[] TMPgetCoordsFace = getCoordsFace;
final int[][][]TMPfaces = faces;

geom[TMPsurff].updateData(new GeometryUpdater() {

public void updateData(Geometry geometry) {

System.out.println("Surff is: " + TMPsurff+" ");

//проходим через все фейсы
for(int ff = 0; ff<(TMPgetCoordsFace[TMPsurff]); ff++){

//point
geom[TMPsurff].setCoordinate((ff*3)+2,
new Point3f(
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[0],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[1],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[2]));

geom[TMPsurff].setCoordinate((ff*3)+1,
new Point3f(
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][1])))[0],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][1])))[1],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][1])))[2]));

geom[TMPsurff].setCoordinate((ff*3)+0,
new Point3f(
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][2])))[0],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][2])))[1],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][2])))[2]));

}

}
});

}

public void updateData(Geometry geometry) {

// only for:The type shape3dcreator must implement the inherited abstract method GeometryUpdater.updateData(Geometry)

}[/i]

So, at your option, is it right for Java3D? Or it contains mistakes?

kcr
Offline
Joined: 2004-03-17

> So, at your option, is it right for Java3D? Or it contains mistakes?

It contains at least one mistake. The calls to setCoordinate only work for by-copy data (they throw an exception for by-ref data). For by-ref, you modify the referenced arrays directly, but only within a GeometryUpdater.

I recommend taking a look at some example or tutorial code.

-- Kevin

code`poet
Offline
Joined: 2006-02-17

Hmm, I understood something :)
But it doesnt work.

So. I understand that [i]GeometryArray ta = (GeometryArray) geometry[/i] is a link to the memory in video card and I work with it. So I must to change all geometry in one updateData, because I cant do so [i]geom[surff].updateData(...) [/i], because of I will have only the last geom on the screen. But the question is how to merge geom[surff] in one geom?

The code I use:

[b]In the main class:
[/b]
[i]for(int s =0; s sh3d.cd.setIsDirty(true);[/i]

[b]In another one:[/b]
[i]public void UpdateMyData(int getSurfaceN, int[] getCoordsFaceN,int[][][] facesN) {

System.out.println("Updating data...");

final int surff = getSurfaceN;
final int[] getCoordsFace = getCoordsFaceN;
final int[][][]faces = facesN;

geom[surff].updateData(new GeometryUpdater() {

public void updateData(Geometry geometry) {

ta = (GeometryArray)geometry;
cd = ta.getCoordinateData();

FloatBuffer fbc = cd.getFloatBuffer();
fbc.rewind();

System.out.println("Surff is: " + surff+" ");

//проходим через все фейсы
for(int ff = 0; ff<(getCoordsFace[surff]); ff++){
//point

fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][0])))[0]);
fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][0])))[1]);
fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][0])))[2]);

fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][1])))[0]);
fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][1])))[1]);
fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][1])))[2]);

fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][2])))[0]);
fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][2])))[1]);
fbc.put(((float[])(((ArrayList)listOfSurff.get(surff)).get(faces[surff][ff][2])))[2]);

/*

cd.setFloats((ff*3)+0,
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[0],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[1],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][0])))[2]);

cd.setFloats((ff*3)+1,
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][1])))[0],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][1])))[1],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][1])))[2]);

cd.setFloats((ff*3)+2,
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][2])))[0],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][2])))[1],
((float[])(((ArrayList)listOfSurff.get(TMPsurff)).get(TMPfaces[TMPsurff][ff][2])))[2]);*/
//cd.setIsDirty(true);
}

}
});

}
[/i]