org.jcae.viewer3d.post
Class TextureFitter

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by javax.media.j3d.Canvas3D
              extended by org.jcae.viewer3d.View
                  extended by org.jcae.viewer3d.post.TextureFitter
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, PositionListener

public class TextureFitter
extends View

A special View which allows to fit a texture on a given geometry. It helps to compute the transformation which will match the texture on the geometry. The texture is mapped with an orthogonal projection on the geometry. The projection is done by OpenGL. The transformation applied on the texture before being projected is computed using 2 user specified triangles, one in the geometry space (3D) and one in the texture space (3D with z=0). If the specified triangles are not similar (the angles of one are equal to the corresponding angles of the other) the computed transformation is normalized to ensure that the projection is not deformant.

See Also:
Serialized Form

Nested Class Summary
static class TextureFitter.PickViewableCAD
          A special ViewableCAD which allows picking points on a surface.
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class org.jcae.viewer3d.View
BACK, BackClipDistanceFactor, BOTTOM, FRONT, FrontClipDistanceFactor, LEFT, orbit, RIGHT, TOP
 
Fields inherited from class javax.media.j3d.Canvas3D
FIELD_ALL, FIELD_LEFT, FIELD_RIGHT
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TextureFitter(java.awt.Window frame)
           
 
Method Summary
static void displayMatrixInfo(javax.vecmath.Matrix4d matrix)
           
 Viewable displayTexture(org.jcae.opencascade.jni.TopoDS_Shape shape, javax.vecmath.Point3d[] triangle2d, javax.vecmath.Point3d[] triangle3d, java.awt.image.BufferedImage image)
          Display the texture with a normalized projection
 Viewable displayTexture(org.jcae.opencascade.jni.TopoDS_Shape shape, javax.vecmath.Point3d[] triangle2d, javax.vecmath.Point3d[] triangle3d, java.awt.image.BufferedImage image, boolean normalize)
           
 Viewable drawPoint(double x, double y, double z)
           
static void getEulerAngles(javax.vecmath.Tuple3d angles, javax.vecmath.Quat4d q1)
          from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/
static double getOrthogonality(javax.vecmath.Matrix4d m)
          Return the sum in absolute value of scalar product of column vector of the matrix.
static javax.vecmath.Vector3d getScaling(javax.vecmath.Matrix4d m)
          Return the scaling factor in the 3 direction for the given transformation.
static org.jcae.opencascade.jni.TopoDS_Compound getSelectFaces(ViewableCAD viewable, org.jcae.opencascade.jni.TopoDS_Shape shape)
          Return selected faces in a viewable
static javax.vecmath.Matrix4d getTransform(javax.vecmath.Point3d[] dst, javax.vecmath.Point3d[] src)
          Compute the normalized transformation of triangle src to triangle dst
static javax.vecmath.Matrix4d getTransform(javax.vecmath.Point3d[] dst, javax.vecmath.Point3d[] src, boolean normalize)
          Compute the transformation of triangle src to triangle dst
 void print3DProperties(java.io.PrintStream out)
          Display 3D properties for debugging purpose It use Canvas3D.queryProperties
 void removeTexture(Viewable viewable)
           
 void updateTexture(Viewable viewable, javax.vecmath.Point3d[] triangle2d, javax.vecmath.Point3d[] triangle3d)
          Move the texture.
 void updateTexture(Viewable viewable, javax.vecmath.Point3d[] triangle2d, javax.vecmath.Point3d[] triangle3d, boolean normalize)
          Move the texture
 
Methods inherited from class org.jcae.viewer3d.View
add, addBranchGroup, addPositionListener, addPostRenderer, addUnClipWidgetBranchGroup, addWidgetBranchGroup, contains, finalize, firePositionChanged, fireViewableChanged, fit, fitAll, getBackClipDistance, getBound, getBranchGroup, getCurrentViewable, getFrontClipDistance, getImage, getMouseMode, getOriginAxisTransformGroup, getRotationCenter, getViewables, getViewingPlatform, isInModelClip, isOriginAxisVisible, move, positionChanged, postRender, postSwap, println, remove, removeModelClip, removePostRenderer, removeUnClipWidgetBranchGroup, removeWidgetBranchGroup, restoreFrontClipDistance, setBackClipDistance, setChangeRotationCenter, setClipBox, setClipPlanes, setCurrentViewable, setFixedAxisVisible, setFrontClipDistance, setMouseMode, setNavigationMaster, setOrientation, setOriginAxisVisible, setPickableViewables, setPickingMode, setPrintWriter, setRotationCenter, startRenderer, stopRenderer, takeScreenshot, takeSnapshot, takeSnapshot, viewableChanged, where, zoomTo
 
Methods inherited from class javax.media.j3d.Canvas3D
addNotify, getBounds, getBounds, getCenterEyeInImagePlate, getDoubleBufferAvailable, getDoubleBufferEnable, getGraphics2D, getGraphicsContext3D, getHeight, getImagePlateToVworld, getInverseVworldProjection, getLeftEyeInImagePlate, getLeftManualEyeInImagePlate, getLocation, getLocation, getLocationOnScreen, getMonoscopicViewPolicy, getOffScreenBuffer, getOffScreenLocation, getOffScreenLocation, getPhysicalHeight, getPhysicalWidth, getPixelLocationFromImagePlate, getPixelLocationInImagePlate, getPixelLocationInImagePlate, getRightEyeInImagePlate, getRightManualEyeInImagePlate, getSceneAntialiasingAvailable, getScreen3D, getSize, getSize, getStereoAvailable, getStereoEnable, getView, getVworldProjection, getVworldToImagePlate, getWidth, getX, getY, isOffScreen, isRendererRunning, isShadingLanguageSupported, paint, preRender, queryProperties, removeNotify, renderField, renderOffScreenBuffer, setDoubleBufferEnable, setLeftManualEyeInImagePlate, setMonoscopicViewPolicy, setOffScreenBuffer, setOffScreenLocation, setOffScreenLocation, setRightManualEyeInImagePlate, setStereoEnable, startRenderer, stopRenderer, swap, waitForOffScreenRendering
 
Methods inherited from class java.awt.Canvas
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextureFitter

public TextureFitter(java.awt.Window frame)
Parameters:
frame - the window owning the widget
Method Detail

getSelectFaces

public static org.jcae.opencascade.jni.TopoDS_Compound getSelectFaces(ViewableCAD viewable,
                                                                      org.jcae.opencascade.jni.TopoDS_Shape shape)
Return selected faces in a viewable

Parameters:
viewable - The viewable on witch picking has been done
shape - The shape from which faces are selected. This is the one used to create the viewable.
Returns:
A compound including all selected faces

getTransform

public static javax.vecmath.Matrix4d getTransform(javax.vecmath.Point3d[] dst,
                                                  javax.vecmath.Point3d[] src)
Compute the normalized transformation of triangle src to triangle dst

Parameters:
dst - The 3 transformed points
src - The 3 points to transform

getTransform

public static javax.vecmath.Matrix4d getTransform(javax.vecmath.Point3d[] dst,
                                                  javax.vecmath.Point3d[] src,
                                                  boolean normalize)
Compute the transformation of triangle src to triangle dst

Parameters:
dst - The 3 transformed points
src - The 3 points to transform
true - to normalize the transformation

getScaling

public static javax.vecmath.Vector3d getScaling(javax.vecmath.Matrix4d m)
Return the scaling factor in the 3 direction for the given transformation. For texture fitting the 3 values should be equals, so using this method is a way to control the validity of the input points.

Returns:
a vector containing scaling for x, y and z

getOrthogonality

public static double getOrthogonality(javax.vecmath.Matrix4d m)
Return the sum in absolute value of scalar product of column vector of the matrix. A value close to 0 means that the input points used to define the texture fitting are good. A big value means they are not.


displayMatrixInfo

public static void displayMatrixInfo(javax.vecmath.Matrix4d matrix)

getEulerAngles

public static void getEulerAngles(javax.vecmath.Tuple3d angles,
                                  javax.vecmath.Quat4d q1)
from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/


displayTexture

public Viewable displayTexture(org.jcae.opencascade.jni.TopoDS_Shape shape,
                               javax.vecmath.Point3d[] triangle2d,
                               javax.vecmath.Point3d[] triangle3d,
                               java.awt.image.BufferedImage image)
Display the texture with a normalized projection

Parameters:
shape - The shape on which the texture must be displayed
triangle2d - The 2D points (z=0) picked on the bitmap
triangle3d - The 3D points picked on the geometry
image - The image to display
true - to normalize

displayTexture

public Viewable displayTexture(org.jcae.opencascade.jni.TopoDS_Shape shape,
                               javax.vecmath.Point3d[] triangle2d,
                               javax.vecmath.Point3d[] triangle3d,
                               java.awt.image.BufferedImage image,
                               boolean normalize)
Parameters:
shape - The shape on which the texture must be displayed
triangle2d - The 2D points (z=0) picked on the bitmap
triangle3d - The 3D points picked on the geometry
image - The image to display
true - to normalize
Returns:

removeTexture

public void removeTexture(Viewable viewable)

updateTexture

public void updateTexture(Viewable viewable,
                          javax.vecmath.Point3d[] triangle2d,
                          javax.vecmath.Point3d[] triangle3d)
Move the texture. The projection is normalized.

Parameters:
triangle2d - The 2D points (z=0) picked on the bitmap
triangle3d - The 3D points picked on the geometry

updateTexture

public void updateTexture(Viewable viewable,
                          javax.vecmath.Point3d[] triangle2d,
                          javax.vecmath.Point3d[] triangle3d,
                          boolean normalize)
Move the texture

Parameters:
triangle2d - The 2D points (z=0) picked on the bitmap
triangle3d - The 3D points picked on the geometry
true - to normalize

print3DProperties

public void print3DProperties(java.io.PrintStream out)
Display 3D properties for debugging purpose It use Canvas3D.queryProperties

Parameters:
out - The PrintStream where to print (i.e. System.out)

drawPoint

public Viewable drawPoint(double x,
                          double y,
                          double z)