Surfaces from Generated Points

Have jReality programming problems or questions? Post them here.
Post Reply
karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Surfaces from Generated Points

Post by karunaMaitri » Tue 9. Dec 2008, 09:39

Hi,

I have been trying to render surfaces from a set of data points generated from another program, instead of using equations. I was able to write an application - a jReality program that works by using ParametricSurfaceFactory. This is similar to one of the tutorial examples on the jReality web site. I added my code at the end of this message.

I have three problems in extending the code.

1. In my code, I have generated u and v parameter values and stored them in a data structure along with the (x, y, z) coordinates. As I understand, the ParametricSurfaceFactory calls evaluate method of Immersion by generating u and v values. If the parameter values I generate are different from those of ParSurFactory (even in decimal points), the points are not recognized. This is very constraining as in my data generation I would like to have the freedom to choose increments in parametric values (some times non-uniform) and precision as dictated by my problem. Is there a solution to this problem?

2. I have problem setting up various appearance attributes for the surface. I realize that I have to create scene graph node to attach the appearance node and give colors. But I did not have success. Do you have an example program that illustrates this point for surfaces? I have looked at the tutorial examples. I would like to render surfaces that are smooth (filled) and mesh, as in OpenGL.

3. I have tried to use ParametricTriangularSurfaceFactory but without much success. I have set Immersion and then added the following code.
psf.setUVTriangle(new double[][]{{0.0,0.0}, {0.05, 0.0}, {0.0, 0.05}});
psf.setUVTriangle(points);
I do not know how to coordinate my parameter bounds and increments with those of the Factory class. How can I do this?

Here is my code for the ParSurFactory class.

public class SurfaceMyPointsTest {
private double[][] points;
private int uCount = 0;
private int vCount = 0;

public static void main(String[] args) {
SurfaceMyPointsTest test = new SurfaceMyPointsTest();
}

public SurfaceMyPointsTest() {
uCount = 20;
vCount = 20;
generate3DPoints(-0.5, 0.5, -0.5, 0.5);
ParametricSurfaceFactory psf = new ParametricSurfaceFactory(new B_SplineSurface(), 1);
psf.setClosedInUDirection(true);
psf.setClosedInVDirection(true);
psf.setGenerateVertexNormals(true);
//set parameters
psf.setUMin(-0.5);
psf.setUMax(0.5);
psf.setVMin(-0.5);
psf.setVMax(0.5);
psf.setULineCount(uCount);
psf.setVLineCount(vCount);
psf.setGenerateEdgesFromFaces(true);
psf.setGenerateVertexNormals(true);

psf.update();
ViewerApp va = ViewerApp.display(psf.getIndexedFaceSet());
CameraUtility.encompass(va.getCurrentViewer());

}

public double[][] generate3DPoints(double minU, double maxU, double minV, double maxV) {

double quarterU = (maxU - minU) / 4.0;
double quarterV = (maxV - minV) / 4.0;
double threeQuartU = (maxU - minU) * 3.0 / 4.0;
double threeQuartV = (maxV - minV) * 3.0 / 4.0;
double midPointU = (maxU - minU) / 2.0;
double midPointV = (maxV - minV) / 2.0;

points = new double[uCount * vCount][5];
double u = minU;
double v = minV;
double incU = (double) (maxU - minU) / (double) uCount;
double incV = (double) (maxV - minV) / (double) vCount;
int k = 0;

for (int i = 0; i < uCount; i++) {
for (int j = 0; j < vCount; j++) {
double[] point = new double[3];
if ((u > threeQuartU) || (v > threeQuartV) || (u < quarterU) || (v < quarterV)) {
point[0] = u;
point[1] = v;
point[2] = 0.0f;
}
else if (u < midPointU) {
point[0] = u;
point[1] = v;
point[2] = u;

}
else if (v < midPointV) {
point[0] = u;
point[1] = v;
point[2] = v;

}
else if (u > midPointU) {
point[0] = u;
point[1] = v;
point[2] = (maxU - minU) - u;

}
else if (v > midPointV) {
point[0] = u;
point[1] = v;
point[2] = (maxV - minV) - v;

}
else if ((u == midPointU) || (v == midPointV)) {
point[0] = u;
point[1] = v;
point[2] = u;

}
double[] uvPoint = new double[]{u, v, point[0], point[1], point[2]};

System.out.println("Point " + k + "=> u: " + uvPoint[0] + ", v: " + uvPoint[1] + ", x: " + uvPoint[2] + ", y: " + uvPoint[3] + ", z: " + uvPoint[4]);
points[k] = uvPoint;
k++;
v = roundTwoDecimals(v + incV);
}
v = minV;
u = roundTwoDecimals(u + incU);
}
return points;
}

public double roundTwoDecimals(double d) {
DecimalFormat twoDForm = new DecimalFormat("#.##");
return Double.valueOf(twoDForm.format(d));
}

public class B_SplineSurface implements Immersion {
int l = 0;
public void evaluate(double u, double v, double[] xyz, int index) {
double u1 = roundTwoDecimals(u);
double v1 = roundTwoDecimals(v);
double[] uvPoint = getElement(u1, v1);

if (uvPoint != null){
xyz[index] = uvPoint[2];
xyz[index + 1] = uvPoint[3];
xyz[index + 2] = uvPoint[4];
System.out.println("Point-" + (l++) + ": X= " + xyz[index] + ", Y= " + xyz[index + 1] + ", Z= " + xyz[index + 2]);
}
else
System.out.println("Cannot find: u=" + u1 + ", v=" + v1);
}

private double[] getElement(double u, double v) {
for (int i = 0; i < points.length; i++){
double[] point = points[i];
if (u == point[0] && v == point[1])
return point;
}
System.out.println("Failed to find in points the values: u=" + u + ", v=" + v);
return null;
}

public int getDimensionOfAmbientSpace() {
return 3;
}

public boolean isImmutable() {
return true;
}
}
}


Thank you very much!
Karuna

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Post by gunn » Tue 9. Dec 2008, 17:33

Hello Karuna,

Let's handle your 3 questions separately.

First, regarding theParametricSurfaceFactory: it sounds like you really want to use a more general factory called QuadMeshFactory, that allows you to evaluate your function at the parameter values which you wish. There is an example in the same tutorial directory where you found the ParametricSurfaceExample. It's called QuadMeshExample.

Secondly, regarding setting appearance attributes: there is a introductory tutorial example ViewerAppDemo in the package de.jreality.tutorial.intro, which shows several examples of how to set appearances for different purposes. It's a composite example, containing several examples. To run it, invoke it with a command line argument, an integer from 0 to 7. The arguments 2 and 3 show how to set appearance attributes. Be sure to update your jreality distribution first (I'm assuming you're using the svn repository at www.jreality.de) since there have been a few improvements recently.

Thirdly, regarding the ParametricTriangularSurfaceFactory: are you sure you need to use this factory? I can explain how to use it but if your needs are met by the QuadMeshFactory indicated above, then I won't bother to do so. Let me know.

Hope these indications help you,

Charles Gunn
jReality core developer

karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

It worked!

Post by karunaMaitri » Sat 13. Dec 2008, 03:40

Thank you, Charles! I looked at the QuadMeshExample and Ooloid (in examples) for using QuadMeshFactory. It solved my problem. Thank you very much for the very helpful suggestions.

I also looked at the ViewerAppDemo. It is also helpful.

Is there a detailed "functional" notes on jReality that can help us design complex scene graphs that allow user interactions in the scene, and control rendering?

Thanks!
Karuna

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Post by gunn » Tue 16. Dec 2008, 10:44

All the documented code examples that we have are collected in the tutorial folder. I'm aware that there are many topics which are not covered by the tutorial. And there are many code examples floating around among the developers here which could be converted into tutorial examples.

It would help me select an appropriate example, if you would describe in a bit more detail what kind of application you have in mind: the structure of the scene graph and the nature of the user interactions you anticipate implementing. Then I can try either giving some specific recommendations or providing an appropriate code example to help you get started.
jReality core developer

karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Post by karunaMaitri » Sun 21. Dec 2008, 02:21

Thanks Charles! I am sorry for the delayed reply as I have been busy trying to integrate jReality into my system. I have been trying to make notes and drawing UML diagrams from the tutorials and the source code. You are right! Tutorials are very helpful!

The research work I am doing is on Visual Interfaces. The system I am building for this work has a number of modules - and one of the modules is for visualizing the data. That is where jReality plays a role. The modules are isolated except for some functional knowledge of each other. As we progress in our work, we hope to identify this functional knowledge better. I will keep posting messages as I face new problems.

Thanks for all the help!

Karuna

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Post by gunn » Wed 7. Jan 2009, 12:29

If I understand your last post correctly, you will post messages as you encounter new problems. Once I have more specific information about your needs, I will attempt to find appropriate examples that show how jReality might be used to meet those needs.
jReality core developer

karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Post by karunaMaitri » Sat 10. Jan 2009, 22:13

Thank you very much!

Regards,
Karuna

Post Reply