NLMISC::CPolygon2D Class Reference

A 2d convex polygon. More...

#include <polygon.h>

List of all members.

Public Types

typedef std::vector< CVector2fTVec2fVect
typedef std::pair< sint, sintTRaster
typedef std::vector< TRasterTRasterVect

Public Member Functions

 CPolygon2D ()
 default ctor
void swap (CPolygon2D &other)
 CPolygon2D (const CPolygon &src, const CMatrix &projMat=CMatrix::Identity)
 Build a 2D polygon from this 3D polygon, by using the given projection matrix The x and y components of projected vertices are used to create the 2D polygon.
void fromPolygon (const CPolygon &src, const CMatrix &projMat=CMatrix::Identity)
 Reinit a 2D polygon from this 3D polygon, by using the given projection matrix The x and y components of projected vertices are used to create the 2D polygon.
 CPolygon2D (const CTriangle &tri, const CMatrix &projMat=CMatrix::Identity)
 Build a 2D polygon from the given triangle, by using the given projection matrix The x and y components of projected vertices are used to create the 2D polygon.
bool isConvex ()
 Check whether this polygon is convex;.
void buildConvexHull (CPolygon2D &dest) const
 Build a convex hull from this polygon.
void getBestTriplet (uint &index0, uint &index1, uint &index2)
 get the best triplet of vector. e.g the triplet that has the best surface
void serial (NLMISC::IStream &f) throw (NLMISC::EStream)
 Serial this polygon.
void computeBorders (TRasterVect &borders, sint &minimumY) const
 Compute the borders of this poly with sub-pixel accuracy.
void computeOuterBorders (TRasterVect &borders, sint &minimumY) const
 The same as compute borders, but pixel are seen as surfaces and not as points.
void computeInnerBorders (TRasterVect &borders, sint &minimumY) const
 The same as compute borders, but pixel are seen as surfaces and not as points In this version, only pixels that are entirely INSIDE the poly are kept IMPORTANT: coordinates must be in the -32000, 32000 range.
bool intersect (const CPolygon2D &other) const
 Test whether this polygon intersect another convex polygon. Currently not optimized.
bool contains (const CVector2f &p, bool hintIsConvex=true) const
 Check whether a point is contained by this poly.
bool getNonNullSeg (uint &seg) const
 Get the index of a segment of this poly that is a non null segment.
void getLineEquation (uint index, float &a, float &b, float &c) const
 Get a line equation of the seg starting at the given index.
bool isCCWOriented () const
void getBoundingRect (CVector2f &minCorner, CVector2f &maxCorner) const
bool selfIntersect () const

Public Attributes

TVec2fVect Vertices

Private Member Functions

float sumDPAgainstLine (float a, float b, float c) const
 Sum the dot product of this poly vertices against a line equation a*x + b*y + c.
const CVector2fgetSegRef0 (uint index) const
 Get ref to the first vertex that start at index.
const CVector2fgetSegRef1 (uint index) const
void checkValidBorders () const

Detailed Description

A 2d convex polygon.

Definition at line 125 of file polygon.h.


Member Typedef Documentation

typedef std::pair<sint, sint> NLMISC::CPolygon2D::TRaster

Definition at line 167 of file polygon.h.

Definition at line 168 of file polygon.h.

Definition at line 128 of file polygon.h.


Constructor & Destructor Documentation

NLMISC::CPolygon2D::CPolygon2D (  )  [inline]

default ctor

Definition at line 132 of file polygon.h.

NLMISC::CPolygon2D::CPolygon2D ( const CPolygon src,
const CMatrix projMat = CMatrix::Identity 
)

Build a 2D polygon from this 3D polygon, by using the given projection matrix The x and y components of projected vertices are used to create the 2D polygon.

Definition at line 839 of file polygon.cpp.

References fromPolygon().

NLMISC::CPolygon2D::CPolygon2D ( const CTriangle tri,
const CMatrix projMat = CMatrix::Identity 
)

Build a 2D polygon from the given triangle, by using the given projection matrix The x and y components of projected vertices are used to create the 2D polygon.

Definition at line 2159 of file polygon.cpp.

References NLMISC::CTriangle::V0, NLMISC::CTriangle::V1, NLMISC::CTriangle::V2, and Vertices.


Member Function Documentation

void NLMISC::CPolygon2D::buildConvexHull ( CPolygon2D dest  )  const

Build a convex hull from this polygon.

The result poly is ordered, so it can also be used to order a convex poly given its set of vertices. NB: require this != &dest

Definition at line 895 of file polygon.cpp.

References NLMISC::n, nlassert, Vertices, and NLMISC::CVector2f::y.

void NLMISC::CPolygon2D::checkValidBorders (  )  const [private]

Definition at line 1978 of file polygon.cpp.

References nlassert, and Vertices.

Referenced by computeBorders(), computeInnerBorders(), and computeOuterBorders().

void NLMISC::CPolygon2D::computeBorders ( TRasterVect borders,
sint minimumY 
) const

Compute the borders of this poly with sub-pixel accuracy.

No clipping is performed. Only points exactly inside or exactly on the left border of the polygon are kept. This means that pixels are seen as points, not as surfaces. The output is in a vector of sint pairs. minimumY is filled with the minimum y value of the poly. Each pairs gives [xmin, xmax] for the current segment. if xmin > xmax, then no point is valid for this segment. Otherwise, all points from x = xmin (included) to x = xmax (included) are valid. IMPORTANT: coordinates must be in the -32000, 32000 range. This is checked in debug

check poly height, and discard null height

Definition at line 1201 of file polygon.cpp.

References checkValidBorders(), NLMISC::Next(), NLMISC::Prev(), NLMISC::ScanEdge(), swap(), and Vertices.

Referenced by NL3D::CLodCharacterShapeBuild::compile(), and RenderTriangle().

void NLMISC::CPolygon2D::computeInnerBorders ( TRasterVect borders,
sint minimumY 
) const

The same as compute borders, but pixel are seen as surfaces and not as points In this version, only pixels that are entirely INSIDE the poly are kept IMPORTANT: coordinates must be in the -32000, 32000 range.

This is checked in debug

Definition at line 1792 of file polygon.cpp.

References checkValidBorders(), min, NLMISC::ScanInnerEdge(), swap(), Vertices, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

Referenced by NL3D::CWaterModel::getNumWantedVertices().

void NLMISC::CPolygon2D::computeOuterBorders ( TRasterVect borders,
sint minimumY 
) const

The same as compute borders, but pixel are seen as surfaces and not as points.

Any pixel that is touched by the poly will be selected IMPORTANT: coordinates must be in the -32000, 32000 range. This is checked in debug

Definition at line 1501 of file polygon.cpp.

References checkValidBorders(), min, nlassert, NLMISC::ScanOuterEdgeLeft(), NLMISC::ScanOuterEdgeRight(), swap(), Vertices, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

Referenced by NL3D::addQuadToSilhouette(), NL3D::CPackedZone32::addTri(), NL3D::CPackedZone32::appendSelection(), NL3D::CPackedZone16::appendSelection(), NL3D::CQuadGrid< T >::buildSelectionShape(), NL3D::CWaterModel::getNumWantedVertices(), and NL3D::CPackedWorld::select().

bool NLMISC::CPolygon2D::contains ( const CVector2f p,
bool  hintIsConvex = true 
) const

Check whether a point is contained by this poly.

contains the seg 2d equation

Definition at line 2090 of file polygon.cpp.

References getLineEquation(), getSegRef0(), getSegRef1(), nlassert, Vertices, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

Referenced by intersect().

void NLMISC::CPolygon2D::fromPolygon ( const CPolygon src,
const CMatrix projMat = CMatrix::Identity 
)

Reinit a 2D polygon from this 3D polygon, by using the given projection matrix The x and y components of projected vertices are used to create the 2D polygon.

Definition at line 845 of file polygon.cpp.

References Vertices, NLMISC::CPolygon::Vertices, NLMISC::CVector::x, and NLMISC::CVector::y.

Referenced by CPolygon2D().

void NLMISC::CPolygon2D::getBestTriplet ( uint index0,
uint index1,
uint index2 
)

get the best triplet of vector. e.g the triplet that has the best surface

Definition at line 1026 of file polygon.cpp.

References nlassert, Vertices, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

void NLMISC::CPolygon2D::getBoundingRect ( CVector2f minCorner,
CVector2f maxCorner 
) const
void NLMISC::CPolygon2D::getLineEquation ( uint  index,
float a,
float b,
float c 
) const

Get a line equation of the seg starting at the given index.

Definition at line 2038 of file polygon.cpp.

References getSegRef0(), getSegRef1(), nlassert, Vertices, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

Referenced by contains(), and intersect().

bool NLMISC::CPolygon2D::getNonNullSeg ( uint seg  )  const

Get the index of a segment of this poly that is a non null segment.

Returns:
true if such a segment was found

Definition at line 2004 of file polygon.cpp.

References nlassert, and Vertices.

Referenced by intersect().

const CVector2f& NLMISC::CPolygon2D::getSegRef0 ( uint  index  )  const [inline, private]

Get ref to the first vertex that start at index.

Definition at line 217 of file polygon.h.

References nlassert, and Vertices.

Referenced by contains(), getLineEquation(), intersect(), and selfIntersect().

const CVector2f& NLMISC::CPolygon2D::getSegRef1 ( uint  index  )  const [inline, private]

Definition at line 221 of file polygon.h.

References nlassert, and Vertices.

Referenced by contains(), getLineEquation(), intersect(), and selfIntersect().

bool NLMISC::CPolygon2D::intersect ( const CPolygon2D other  )  const

Test whether this polygon intersect another convex polygon. Currently not optimized.

get the orientation of this poly

contains the seg 2d equation

don't check against a null segment

get the line equation of the current segment

contains the seg 2d equation

Definition at line 2051 of file polygon.cpp.

References contains(), getLineEquation(), getNonNullSeg(), getSegRef0(), getSegRef1(), nlassert, sumDPAgainstLine(), Vertices, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

Referenced by NL3D::CZoneLighter::computeTileFlagsForPositionTowardWater().

bool NLMISC::CPolygon2D::isCCWOriented (  )  const

Definition at line 1135 of file polygon.cpp.

References NLMISC::Next(), nlassert, NLMISC::Prev(), and Vertices.

Referenced by NL3D::CWaterModel::getNumWantedVertices().

bool NLMISC::CPolygon2D::isConvex (  ) 

Check whether this polygon is convex;.

Definition at line 857 of file polygon.cpp.

References NLMISC::CVector::K, NLMISC::CPlane::make(), NLMISC::n, NLMISC::CVector::set(), and Vertices.

bool NLMISC::CPolygon2D::selfIntersect (  )  const

Definition at line 2231 of file polygon.cpp.

References getSegRef0(), getSegRef1(), NLMISC::testSegmentIntersection(), and Vertices.

void NLMISC::CPolygon2D::serial ( NLMISC::IStream f  )  throw (NLMISC::EStream)

Serial this polygon.

Definition at line 1018 of file polygon.cpp.

References void().

float NLMISC::CPolygon2D::sumDPAgainstLine ( float  a,
float  b,
float  c 
) const [private]

Sum the dot product of this poly vertices against a line equation a*x + b*y + c.

Sum the dot product of this poly vertices against a plane.

Definition at line 1991 of file polygon.cpp.

References Vertices, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

Referenced by intersect().

void NLMISC::CPolygon2D::swap ( CPolygon2D other  )  [inline]

Definition at line 135 of file polygon.h.

References Vertices.

Referenced by computeBorders(), computeInnerBorders(), and computeOuterBorders().


Member Data Documentation


The documentation for this class was generated from the following files:

Generated on Thu Jan 7 08:30:18 2010 for NeL by  doxygen 1.6.1