You are here: AGGeom » JavaView » JVCommonTasks

JVCommonTasks

This page presents some common tasks during the basic coding workflow with the JavaView library.

Copying Geometries

To copy a geometry you should use the copy() method provided by each geometry class. This needs a cast in the argument of the copy method.

PgElementSet geom = new PgElementSet(3);
geom.setName("Torus");
geom.computeTorus(10, 10, 2., 1.);

PgElementSet geomCopy = new PgElementSet();
geomCopy.copy((PgElementSet) geom);

A similar method is provided by other geometry type classes. See also Clone vs. Copy

Create Geometry from Scratch

Compute Default Geometries

PgElementSet provides several member methods to compute some default geometries such as spheres or tori with prescribed resolution.

PgElementSet geom = new PgElementSet(3);
geom.setName("Torus");
// Compute a torus with radius 2 and transversal radius 1
// with 10 x 10 grid lines.
geom.computeTorus(10, 10, 2., 1.);
Other default geometry methods include
geom.computeCone(...)
geom.computeCylinder(...)
geom.computePlane(...)
geom.computeSphere(...)

See the http://javaview.de/doc/reference/jv/geom/PgElementSet.html reference API entry for more methods.

Remove duplicated Vertices and Elements

Adding/Removing/Selecting Geometries from Display

When working in a PjProject==-derived class, the member method ==getGeometry() returns the currently active geometry in the project display. Since the project does not know about the geometry type, the method returns a generic PgGeometryIf interface that needs to be cast to a specific geometry type such as PgElementSet, depending on its actual type.

Another option is via access to the m_display member variable of the PjProject class. This variable represents the display associated to the project and thus provides access to various display methods such as adding, selecting or removing certain geometries:

// Add a new geometry to display. 
// Can be of any type (PgPointSet, PgPolygon, PgElementSet,...)
m_display.addGeometry(myGeom);

// Return currently selected geometry.
m_display.getSelectedGeometry();

// Selects the given geometry.
m_display.selectGeometry(myGeom);

// Removes the given geometry from the display.
m_display.removeGeometry(myGeom);

// Cleans the display by removing all geometries.
m_display.removeGeometries();

Similar methods are available for light sources and cameras. See the http://javaview.de/doc/reference/jv/viewer/PvDisplay.html reference API entry for more methods.

Comments

 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback