Scaling up problem for displaying points

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

Scaling up problem for displaying points

Post by karunaMaitri » Thu 9. Feb 2012, 02:43

I am trying to display a (relatively) large (209) set of groups of points. I took some code from geom tutorials and then tried on a simple set of groups of points.

Code: Select all

 double [][] vertices1 = new double[][] {
	    		{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}};
double [][] vertices2 = new double[][] {
	    		{0, 0, 0}, {2, 0, 0}, {2, 2, 0}, {0, 2, 0}};
double [][] vertices3 = new double[][] {
	    		{0, 0, 0}, {0, 3, 0}, {3, 0, 0}, {3, 3, 0}};
double[][][] vertices = new double[3][][];
vertices[0] = vertices1;
vertices[1] = vertices2;
vertices[2] = vertices3; 
It worked fine - the visualization shows all points along with labels. When I tried the same program with 209 points (single group), the same program shows no points or labels. I tried with the disabled labels. The result is the same.

Here is the code I created from "geom" tutorials.

1. I took each group of points from the set of groups of points and then created PointSetFactory for that group.

Code: Select all

factory = new PointSetFactory();
factory.setVertexCount(vertexCount);
factory.setVertexCoordinates(points);
factory.update();


2. Then I set up appearance and labels for this group of points
Here,
ps: PointSet
cmp: SceneGraphComponent

Code: Select all

label(ps, points);
Appearance a = new Appearance();
cmp.setAppearance(a);
cmp.setGeometry(ps);
DefaultGeometryShader dgs = ShaderUtility.createDefaultGeometryShader(
				a, false);
DefaultPointShader dps = (DefaultPointShader) dgs.getPointShader();
dps.setDiffuseColor(color);
dgs.setShowFaces(false);
dgs.setShowLines(false);
dgs.setShowPoints(true);

DefaultTextShader pts = (DefaultTextShader) dps.getTextShader();
pts.setDiffuseColor(Color.blue);

Double scale = new Double(0.01);
pts.setScale(.75 * scale);
double[] offset = new double[] { -.1, 0, 0.3 };
pts.setOffset(offset);
pts.setAlignment(SwingConstants.NORTH_WEST);
Font f = new Font("SansSerif", Font.PLAIN, 20);
pts.setFont(f);

Here the label() method is:

Code: Select all

int n = ps.getNumPoints();
ps.getVertexAttributes(Attribute.COORDINATES).toDoubleArrayArray();
String[] labels = new String[n];
for (int i = 0; i < n; i++)
	labels[i] = "[" + points[i][0] + ", " + points[i][1] + ", " + points[i][2] + "]";
ps.setVertexAttributes(Attribute.LABELS,
				StorageModel.STRING_ARRAY.createReadOnly(labels));
3. Then I added this SceneGraphComponent as a child to a root (SceneGraphComponent)

Code: Select all

root.addChild(node);
4. Then I tried to display the root SceneGraphComponent

Code: Select all

JRViewer.display(root);
Please help me to find where the problem is for the large set of points. My program works fine on small sets.

Thanks,
Karuna

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: Scaling up problem for displaying points

Post by Andre » Thu 9. Feb 2012, 11:20

have you tried to fly/walk around(better ahead)? Maybe the points are just scaled to smaller size. I'll try to rebuild your problem later.

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: Scaling up problem for displaying points

Post by Andre » Thu 9. Feb 2012, 19:14

How I wrote, the points are there, but to far spread. My example shows you left the starting view, in the middle I used the zoom-tool (Camera -> Zoom-tool) and zoomed into the scene and at the righten side I used a smaller scalingfactor to shrink down the vertex positions to a smaler area.

Code: Select all

import java.util.Random;

import de.jreality.geometry.PointSetFactory;
import de.jreality.plugin.JRViewer;

public class Cube01 {
  
  public static void main(String[] args) {
    
    PointSetFactory psf = new PointSetFactory();
    int numVtx = 300;
    double [][] vertices = new double[numVtx][3];
    Random rand = new Random();
    [b]double fac = 1.;[/b]
    for (int i=0;i<numVtx;i++){
    	vertices[i][0]= rand.nextDouble()*fac;
    	vertices[i][1]= rand.nextDouble()*fac;
    	vertices[i][2]= rand.nextDouble()*fac;
    }
    
    psf.setVertexCount( vertices.length );
    psf.setVertexCoordinates( vertices );
    psf.update();
    JRViewer.display(psf.getPointSet());
  }
}
you should probably use a factor to scale your spread-vertices. With fac=1 (righten side) I can see them in my scene, with fac=25 (left/middle) I can't see anything
Attachments
example_pointset.png
example_pointset.png (47.95 KiB) Viewed 1038 times

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

Re: Scaling up problem for displaying points

Post by karunaMaitri » Fri 10. Feb 2012, 11:48

Thank you for the prompt reply. There seems to be two issues - I am sorry I did not make them clear.
One of the constraints on "point cloud" display is to show the correct coordinates of the points. If we multiply by a factor, as you suggested, the points displayed will not be correct.
You answered the second issue - the reason for not being able to see the points. Thank you!

There is another reason why I do not want to use "factor" as this does not solve the problem in general. I want to display any cloud of points (or any geometry) without having to specify a factor.

I think one way to do this is to use the bounding box and then zoom out such that the bounding box stays within view volume. I am keen on this kind of solution as it can be applied to any geometry. Can you tell me how I can do it, or any other method that address this problem.

Thanks,
Karuna

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

Re: Scaling up problem for displaying points

Post by karunaMaitri » Sun 12. Feb 2012, 20:51

To address the question I raised in my previous post about bringing the bounding box into the viewing volume, I found some code in jReality that can do it. It is in the JRViewer and CameraUtility classes. I took some code from the tutorials and added it to my code. Unfortunately, it is not working - I still cannot see any points (even after manually zooming out).

Code: Select all

JRViewer v = new JRViewer();
v.addBasicUI();
v.addContentSupport(ContentType.Raw);
v.setContent(root);
v.startup();
Viewer vs = v.getPlugin(View.class).getViewer();
CameraUtility.encompass(vs);
Please help!

Karuna

Post Reply