org.atzberger.mango.atz3d
Class Atz3D_Camera

java.lang.Object
  extended by org.atzberger.mango.atz3d.Atz3D_Camera
All Implemented Interfaces:
Atz_XML_SAX_DataHandlerInterface, Atz_XML_Writeable

public class Atz3D_Camera
extends java.lang.Object
implements Atz_XML_Writeable, Atz_XML_SAX_DataHandlerInterface

Represents camera orientation and view for 3D rendering package.

The nomenclature associated with the camera model and projection operations follows the book

"Computer Graphics: Principles and Practice, Second Edition in C by Foley, van Dam, Feiner, and Hughes, Addison-Wesley, 1987.

For the particular definitions see the materials around pg. 237.

We summarise them here:

VRP = View reference point.
VPN = View plane normal
VRC = View reference coodinates
VUP = View up vector (note projected orthogonal to VPN)
DOP = Direction of projection
CW = Center of window
PRP = Projection reference point

winBounds = bounds (ell1, ell2) of the window screen in 2D real-space. (normalized window coordinates go from 0.0 to 1.0)

The internal canonical view used for calculations (after transformation) is oriented with the camera looking down the z-axis, so the view-plane is in the x-y-directions (right-handed coordinate system).

Author:
Paul J. Atzberger
See Also:
http://www.atzberger.org

Field Summary
 double[] cameraCW
           
 double[] cameraVPN
           
 double[] cameraVRP
           
 double[] cameraVUP
           
 double[] cameraWinBounds
           
static int FILE_TYPE_XML
           
static int num_dim
           
static java.lang.String tagXML_Atz3D_Camera
           
static java.lang.String tagXML_cameraCW
           
static java.lang.String tagXML_cameraVPN
           
static java.lang.String tagXML_cameraVRP
           
static java.lang.String tagXML_cameraVUP
           
static java.lang.String tagXML_cameraWinBounds
           
 
Constructor Summary
Atz3D_Camera()
          Create the camera with a default view.
 
Method Summary
 Atz3D_Camera clone()
          Make a copy of the camera
 void exportData(java.lang.String filename, int flagType)
          Export the state of the camera to a data file.
 void exportToXML(java.io.BufferedWriter fid)
          * Export the state of the camera to an XML data file.
 double[] genCameraRotationMatrix()
          Generate the rotation matrix which converts from world coordinate frame to the camera canonical coordinate frame.
 void importData(java.lang.String filename, int flagType)
          Import the camera state from a data file
 void setCameraView(double[] new_cameraVRP, double[] new_cameraVUP, double[] new_cameraVPN, double[] new_cameraCW, double[] new_cameraWinBounds)
          Set the camera view explicitly
 void setDefaultValues()
          Set the default values for the camera view.
 void transformPts_2D_To_Screen(double[] ptsX_2D, java.awt.Dimension screenSize, double[] ptsX_Screen_transformed)
          Use the camera settings to find scaling to screen size
 void transformPts_2D_To_Screen(double[] ptsX_2D, double[] ptsX_Screen_transformed)
          Transform the 3D model to a 2D view suitable for rendering on screen.
 void transformPts_3D_To_2D(double[] ptsX_3D, double[] ptsX_2D)
          Transforms the 3D points to corresponding points in the view plane.
 void XML_characters(char[] ch, int start, int length, Atz_XML_SAX_DataHandler sourceHandler)
          Collect misc.
 void XML_endDocument(Atz_XML_SAX_DataHandler sourceHandler)
          Perform these operations when done parsing an XML file.
 void XML_endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Atz_XML_SAX_DataHandler sourceHandler)
          Perform these operations when encountering the end of an XML tag region.
 java.lang.Object XML_getData()
          Get data associated with the XML parsing just performed.
 void XML_startDocument(Atz_XML_SAX_DataHandler sourceHandler)
          Perform these operations when starting to parse the XML file.
 void XML_startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes, Atz_XML_SAX_DataHandler sourceHandler)
          Perform this operation when starting to parse an XML tag.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

num_dim

public static final int num_dim
See Also:
Constant Field Values

cameraVUP

public double[] cameraVUP

cameraVRP

public double[] cameraVRP

cameraVPN

public double[] cameraVPN

cameraCW

public double[] cameraCW

cameraWinBounds

public double[] cameraWinBounds

FILE_TYPE_XML

public static final int FILE_TYPE_XML
See Also:
Constant Field Values

tagXML_Atz3D_Camera

public static java.lang.String tagXML_Atz3D_Camera

tagXML_cameraVUP

public static java.lang.String tagXML_cameraVUP

tagXML_cameraVRP

public static java.lang.String tagXML_cameraVRP

tagXML_cameraVPN

public static java.lang.String tagXML_cameraVPN

tagXML_cameraCW

public static java.lang.String tagXML_cameraCW

tagXML_cameraWinBounds

public static java.lang.String tagXML_cameraWinBounds
Constructor Detail

Atz3D_Camera

public Atz3D_Camera()
Create the camera with a default view.

Method Detail

setDefaultValues

public void setDefaultValues()
Set the default values for the camera view.


clone

public Atz3D_Camera clone()
Make a copy of the camera

Overrides:
clone in class java.lang.Object
Returns:
copy of this camera class

setCameraView

public void setCameraView(double[] new_cameraVRP,
                          double[] new_cameraVUP,
                          double[] new_cameraVPN,
                          double[] new_cameraCW,
                          double[] new_cameraWinBounds)
Set the camera view explicitly

Parameters:
new_cameraVRP -
new_cameraVUP -
new_cameraVPN -
new_cameraCW -
new_cameraWinBounds -

transformPts_3D_To_2D

public void transformPts_3D_To_2D(double[] ptsX_3D,
                                  double[] ptsX_2D)
Transforms the 3D points to corresponding points in the view plane.


transformPts_2D_To_Screen

public void transformPts_2D_To_Screen(double[] ptsX_2D,
                                      double[] ptsX_Screen_transformed)
Transform the 3D model to a 2D view suitable for rendering on screen. Uses the camera settings to determine a normalized value for the project 2D point in terms of screen coordinates. These coordinates are normalized to the range 0.0 to 1.0 for points within the view windows screen. Values outside can be used to clip display of points.


transformPts_2D_To_Screen

public void transformPts_2D_To_Screen(double[] ptsX_2D,
                                      java.awt.Dimension screenSize,
                                      double[] ptsX_Screen_transformed)
Use the camera settings to find scaling to screen size


genCameraRotationMatrix

public double[] genCameraRotationMatrix()
Generate the rotation matrix which converts from world coordinate frame to the camera canonical coordinate frame. The cameraVPN, cameraVUP, etc... are represented in world coordinates and are used for this.


exportData

public void exportData(java.lang.String filename,
                       int flagType)
Export the state of the camera to a data file.

Parameters:
filename -
flagType -

exportToXML

public void exportToXML(java.io.BufferedWriter fid)
* Export the state of the camera to an XML data file.

Specified by:
exportToXML in interface Atz_XML_Writeable
Parameters:
fid -

importData

public void importData(java.lang.String filename,
                       int flagType)
Import the camera state from a data file

Parameters:
filename -
flagType -

XML_startDocument

public void XML_startDocument(Atz_XML_SAX_DataHandler sourceHandler)
Perform these operations when starting to parse the XML file.

Specified by:
XML_startDocument in interface Atz_XML_SAX_DataHandlerInterface
Parameters:
sourceHandler -

XML_endDocument

public void XML_endDocument(Atz_XML_SAX_DataHandler sourceHandler)
Perform these operations when done parsing an XML file.

Specified by:
XML_endDocument in interface Atz_XML_SAX_DataHandlerInterface
Parameters:
sourceHandler -

XML_startElement

public void XML_startElement(java.lang.String uri,
                             java.lang.String localName,
                             java.lang.String qName,
                             org.xml.sax.Attributes attributes,
                             Atz_XML_SAX_DataHandler sourceHandler)
                      throws org.xml.sax.SAXException
Perform this operation when starting to parse an XML tag.

Specified by:
XML_startElement in interface Atz_XML_SAX_DataHandlerInterface
Parameters:
uri -
localName -
qName -
attributes -
sourceHandler -
Throws:
org.xml.sax.SAXException

XML_characters

public void XML_characters(char[] ch,
                           int start,
                           int length,
                           Atz_XML_SAX_DataHandler sourceHandler)
                    throws org.xml.sax.SAXException
Collect misc. XML characters that are in-between tag regions.

Specified by:
XML_characters in interface Atz_XML_SAX_DataHandlerInterface
Parameters:
ch -
start -
length -
sourceHandler -
Throws:
org.xml.sax.SAXException

XML_endElement

public void XML_endElement(java.lang.String uri,
                           java.lang.String localName,
                           java.lang.String qName,
                           Atz_XML_SAX_DataHandler sourceHandler)
                    throws org.xml.sax.SAXException
Perform these operations when encountering the end of an XML tag region.

Specified by:
XML_endElement in interface Atz_XML_SAX_DataHandlerInterface
Parameters:
uri -
localName -
qName -
sourceHandler -
Throws:
org.xml.sax.SAXException

XML_getData

public java.lang.Object XML_getData()
Get data associated with the XML parsing just performed.

Specified by:
XML_getData in interface Atz_XML_SAX_DataHandlerInterface
Returns:
copy of this camera class