Table of contents

MTPoints

Derived from: BArchivable

Declared in: MTPoints.h

Library: 3DM.so

This class contains a list of points, and the methods to transform them. The points' 3 coordinates (X, Y and Z) are stored, with their colors.


Construction and Destruction


MTPoints

                                                         
  

MTPoints( )
MTPoints( BMessage * archive )
MTPoints( const MTPoints & src )
MTPoints( const MTVector & x , const MTVector & y , const MTVector & z , const MTVector & r , const MTVector & g , const MTVector & b )
MTPoints( unsigned int nPoints , const float * coordinates , const rgb_color * colors )

Construct a new object. The first version builds an empty list, the second one can be used to recreate a list from an archive.

You can also build a MTPoints object with 6 vectors ( MTVector objects). The first 3 vectors (x, y and z) are the points coordinates, between -1 and 1 usually, and the 3 last ones (r, g and b) are the colors, between 0 and 1. The vectors must all have exactly the same size. If they don't, the MTPoints object will be empty.

The last constructor builds a MTPoints object from an array of floats and of rgb_colors. coordinates contains nPoints*3 floats. You must first put in the array the coordinates of the first point, then the coordinates of the second one, etc... This constructor is useful if you want to build an object without using the MTVector class.


~MTPoints

                                                         
  

~MTPoints( )

Destroys the list


Static Functions


Circle

                                                         
  

static MTPoints Circle( unsigned int nPoints )

Creates a white circle, with nPoints points, centered at (0,0,0), radius 1, in the x-y plane.


Instantiate

                                                         
  

static BArchivable * Instantiate( BMessage * archive )

Creates a new list extracted from the given archive. It must have been made with Archive() .


Morphing

                                                         
  

static MTPoints Morphing( MTPoints & p1 , MTPoints & p2 , float f )

Creates a new object, morphing between p1 and p2. f controls the morphing. If f is 0, p1 is returned. If f is 1, p2 is returned. If f is between 0 and 1, a morphing between p1 and p2 is done. You can try values below 0 or after 1, and you can have interesting results...


Segment

                                                         
  

static MTPoints Segment( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , unsigned int nPoints )

Creates a new white segment, with nPoints points. You can change the colors with SetColor() .


Virtual functions


Archive

                                                         
  

virtual status_t Archive( BMessage * archive , bool deep =true )

Stores the points list in the given archive. You can build a new list from this archive with the apporpirate constructor, or by using the Instantiate() static function.


Member functions


Add

                                                         
  

MTPoints & Add( const MTVector & x , const MTVector & y , const MTVector & z , const MTVector & r , const MTVector & g , const MTVector & b )
MTPoints & Add( const MTPoints & points )

Adds to the current list the points given as vectors (x, y, z, r, g and b) or as another MTPoints object (points).


Colors

                                                         
  

inline const rgb_color * Colors( ) const

Returns the color list currently used in the object (one rgb_color per point).


Coordinates

                                                         
  

inline const float * Coordinates( ) const

Returns the coordinates list (3 floats per point: X, Y and Z, in this order).


NumPoints

                                                         
  

inline unsigned int NumPoints( ) const

Returns the number of points in the object.


Project

                                                         
  

BPoint * Project( float depth , BPoint * proj ) const

Projects the 3D Points on a 2D plane. The plane used is a x-y plane at z=0. depth is the distance between the plane and the projection point.

The given proj array of BPoint objectss must be allocated, and big enough. (You can know the number of points with NumPoints() .

This method returns proj.


SetColor

                                                         
  

bool SetColor( const MTPoints & src )
bool SetColor( const MTVector & r , const MTVector & g , const MTVector & b )
bool SetColor( float r , float g , float b )
bool SetColor( const rgb_color & color )
bool SetColor( float r1 , float g1 , float b1 , float r2 , float g2 , float b2 )
bool SetColor( const rgb_color & color1 , const rgb_color & color2 )

Changes the color list of the object. The first version takes the colors - and only the colors - from the object src. The two objects must have the same number of points. The second one takes the colors from 3 MTVector objects. The vectors must have the right length. SetColor() returns true if the colors could be changed, and false if not (if src or r, g and b don't have the right length).

The next two versions take one color and apply it to all the points. They always return true. The last two versions make a gradient between the two given colors. They also return true.

When you use MTVector objects or floats, you must use values between 0 and 1 to represent the colors.


SetCoordinates

                                                         
  

bool SetCoordinates( const MTPoints & src )
bool SetCoordinates( const MTVector & x , const MTVector & y , const MTVector & z )

Changes the coordinates of the points in the object, without changing the colors. The coordinates can be taken from another MTObject , or from 3 MTVector objects. Usually the coordinates are between -1 and 1. Returns true if the change could be done, and false if not (if the lengths of src, or x y and z don't have the right size).


SetTo

                                                         
  

MTPoints & SetTo( const MTPoints & src )
MTPoints & SetTo( const MTVector & x , const MTVector & y , const MTVector & z , const MTVector & r , const MTVector & g , const MTVector & b )
SetTo( unsigned int nPoints , const float * coordinates , const rgb_color * colors )

Replaces the object by a new list. It can be a copy of src, or a new list made with the coordinates stored in the vectors x, y and z (between -1 and 1, usually) and the colors stored in the vectors r, g and b (between 0 and 1 usually).

The last version builds a MTPoints object from an array of floats and of rgb_colors. coordinates contains nPoints*3 floats. You must first put in the array the 3 coordinates of the first point, then the coordinates of the second one, etc... This version is useful if you want to build an object without using the MTVector class.


Transform

                                                         
  

MTPoints & Transform( const MTMatrix & matrix )

Apply a linear transformation to the points stored in the object. Have a look at MTMatrix for more details about matrices.


Operators


=

                                                         
  

inline MTPoints & operator=( const MTPoints & src )

Copies the src list in the current object.


&

                                                         
  

MTPoints operator&( const MTPoints & pts ) const

Creates a new list that contains the points in the current list, and then those in pts. The current object isn't modified. Thus in:

A = B & C

A contains all the points in B and in C. B and C aren't modified.


&=

                                                         
  

inline MTPoints & operator&=( const MTPoints & pts )

Adds the points pts to the current list.

See Add() .


*

                                                         
  

MTPoints operator*( const MTMatrix & matrix ) const

Creates a new list with the points of the current object, transformed with the MTMatrix matrix. The current object isn't modified.


*=

                                                         
  

inline MTPoints & operator*=( const MTMatrix & matrix )

Transform the points stored in the object with the given matrix.

See Transform() .