From Geoff Michel, added support for constrain delaunay triangultion, and osgdelaunay example.
This commit is contained in:
@@ -199,6 +199,7 @@ ifeq ($(PRODUCER_INSTALLED),yes)
|
||||
osgcluster\
|
||||
osgcopy\
|
||||
osgcubemap\
|
||||
osgdelaunay\
|
||||
osgdepthshadow\
|
||||
osgdepthpartition\
|
||||
osgdistortion\
|
||||
|
||||
@@ -2175,6 +2175,36 @@ Package=<4>
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Example osgdelaunay"=.\examples\osgdelaunay\osgdelaunay.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osg
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osgDB
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osgGA
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osgProducer
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osgUtil
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name Core osgText
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Example osgtesselate"=.\examples\osgtesselate\osgtesselate.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
|
||||
101
VisualStudio/examples/osgdelaunay/osgdelaunay.dsp
Normal file
101
VisualStudio/examples/osgdelaunay/osgdelaunay.dsp
Normal file
@@ -0,0 +1,101 @@
|
||||
# Microsoft Developer Studio Project File - Name="Example osgdelaunay" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=Example osgdelaunay - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "osgdelaunay.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "osgdelaunay.mak" CFG="Example osgdelaunay - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Example osgdelaunay - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "Example osgdelaunay - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "Example osgdelaunay - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
MTL=midl.exe
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /Zm200 /c
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 OpenThreadsWin32.lib opengl32.lib /nologo /subsystem:console /pdb:none /machine:I386 /out:"../../../bin/osgdelaunay.exe" /libpath:"../../../lib" /libpath:"../../../../OpenThreads/lib/win32" /libpath:"../../../../Producer/lib" /libpath:"../../../../3rdParty/lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "Example osgdelaunay - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
MTL=midl.exe
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /Zi /Od /I "../../../include" /I "../../../../OpenThreads/include" /I "../../../../Producer/include" /I "../../../../3rdParty/include" /D "_CONSOLE" /D "_MBCS" /D "FL_DLL" /D "WIN32" /D "_DEBUG" /FR /YX /FD /Zm200 /c
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 OpenThreadsWin32d.lib opengl32.lib /nologo /subsystem:console /debug /machine:I386 /nodefaultlib:"libcmt" /out:"../../../bin/osgdelaunayd.exe" /pdbtype:sept /libpath:"../../../lib" /libpath:"../../../../OpenThreads/lib/win32" /libpath:"../../../../Producer/lib" /libpath:"../../../../3rdParty/lib"
|
||||
# SUBTRACT LINK32 /incremental:no
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Example osgdelaunay - Win32 Release"
|
||||
# Name "Example osgdelaunay - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\examples\osgdelaunay\osgdelaunay.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\icons\osg_icon.rc
|
||||
# End Source File
|
||||
# End Target
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Project
|
||||
19
examples/osgdelaunay/GNUmakefile
Normal file
19
examples/osgdelaunay/GNUmakefile
Normal file
@@ -0,0 +1,19 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgdelaunay.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgText -losgGA -losgDB -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
GNUmakefile.inst=GNUmakefile
|
||||
|
||||
EXEC = osgdelaunay
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
|
||||
|
||||
13
examples/osgdelaunay/GNUmakefile.inst
Normal file
13
examples/osgdelaunay/GNUmakefile.inst
Normal file
@@ -0,0 +1,13 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
osgdelaunay.cpp\
|
||||
|
||||
LIBS += -losgProducer -lProducer -losgDB -losgText -losgUtil -losg $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgdelaunay
|
||||
|
||||
INC += $(X_INC)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
1378
examples/osgdelaunay/osgdelaunay.cpp
Normal file
1378
examples/osgdelaunay/osgdelaunay.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -14,22 +14,96 @@
|
||||
#ifndef OSGUTIL_DELAUNAYTRIANGULATOR_
|
||||
#define OSGUTIL_DELAUNAYTRIANGULATOR_
|
||||
|
||||
#include <list>
|
||||
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Array>
|
||||
#include <osg/Referenced>
|
||||
#include <osg/CopyOp>
|
||||
#include <osg/PrimitiveSet>
|
||||
#include <osg/Geometry>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
|
||||
namespace osgUtil
|
||||
{
|
||||
|
||||
/** Utility class that triangulates an irregular network of sample points.
|
||||
/** DelaunayTriangulator: Utility class that triangulates an irregular network of sample points.
|
||||
Just create a DelaunayTriangulator, assign it the sample point array and call
|
||||
its triangulate() method to start the triangulation. Then you can obtain the
|
||||
generated primitive by calling the getTriangles() method.
|
||||
|
||||
Add DelaunayConstraints (or derived class) to control the triangulation edges.
|
||||
*/
|
||||
class OSGUTIL_EXPORT DelaunayConstraint: public osg::Geometry {
|
||||
// controls the edges in a Delaunay triangulation.
|
||||
// constraints can be linear (with width), areal (contains an area)
|
||||
// uses: to replace part of a terrain with an alternative textured model (roads, lakes).
|
||||
// the primitive sets in this are either LINE_LOOP or LINE_STRIP
|
||||
public:
|
||||
DelaunayConstraint() { }
|
||||
|
||||
/** Each primitiveset is a list of vertices which may be closed by joining up to its start
|
||||
* to make a loop. Constraints should be simple lines, not crossing themselves.
|
||||
* Constraints which cross other constraints can cause difficulties - see the example
|
||||
* for methods of dealing with them. */
|
||||
|
||||
/** collect up indices of triangle from delaunay triangles.
|
||||
* The delaunay triangles inside the DelaunayConstraint area can be used to fill
|
||||
* the area or generate geometry that terrain follows the area in some way.
|
||||
* These triangles can form a canopy or a field. */
|
||||
void addtriangle(const int i1,const int i2, const int i3);
|
||||
|
||||
/** Get the filling primitive. One:
|
||||
* triangulate must have bneen called and
|
||||
* two: triangle list is filled when
|
||||
* DelaunayTriangulator::removeInternalTriangles is called.
|
||||
* These return the triangles removed from the delaunay triangulation by
|
||||
* DelaunayTriangulator::removeInternalTriangles. */
|
||||
inline const osg::DrawElementsUInt *getTriangles() const;
|
||||
inline osg::DrawElementsUInt *getTriangles();
|
||||
|
||||
/** Call BEFORE makeDrawable to reorder points to make optimised set
|
||||
*/
|
||||
osg::Vec3Array *getPoints(const osg::Vec3Array *points);
|
||||
|
||||
/** converts simple list of triangles into a drawarray.
|
||||
*/
|
||||
osg::DrawElementsUInt *makeDrawable();
|
||||
|
||||
/** Add vertices and constraint loops from dco
|
||||
* Can be used to generate extra vertices where dco crosses 'this' using
|
||||
* osgUtil::tesselator to insert overlap vertices.
|
||||
*/
|
||||
void merge(DelaunayConstraint *dco);
|
||||
|
||||
/** remove from line the vertices that are inside dco
|
||||
*/
|
||||
void removeVerticesInside(const DelaunayConstraint *dco);
|
||||
|
||||
/** return winding number as a float of loop around testpoint; may use multiple loops
|
||||
* does not reject points on the edge or very very close to the edge */
|
||||
float windingNumber(const osg::Vec3 testpoint) const ;
|
||||
|
||||
/** true if testpoint is internal (or external) to constraint. */
|
||||
virtual bool contains(const osg::Vec3 testpoint) const;
|
||||
virtual bool outside(const osg::Vec3 testpoint) const;
|
||||
|
||||
/** Tesselate the constraint loops so that the crossing points are interpolated
|
||||
* and added to the contraints for the triangulation. */
|
||||
void DelaunayConstraint::handleOverlaps(void);
|
||||
|
||||
protected:
|
||||
virtual ~DelaunayConstraint() {}
|
||||
|
||||
typedef std::vector< int* > trilist; // array of indices in points array defining triangles
|
||||
|
||||
trilist _interiorTris; // list of triangles that fits the area.
|
||||
|
||||
osg::ref_ptr<osg::DrawElementsUInt> prim_tris_; // returns a PrimitiveSet to draw the interior of this DC
|
||||
};
|
||||
|
||||
|
||||
class OSGUTIL_EXPORT DelaunayTriangulator: public osg::Referenced {
|
||||
public:
|
||||
|
||||
@@ -37,6 +111,8 @@ public:
|
||||
explicit DelaunayTriangulator(osg::Vec3Array *points, osg::Vec3Array *normals = 0);
|
||||
DelaunayTriangulator(const DelaunayTriangulator ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
typedef std::vector< osg::ref_ptr<DelaunayConstraint> > linelist;
|
||||
|
||||
/** Get the const input point array. */
|
||||
inline const osg::Vec3Array *getInputPointArray() const;
|
||||
|
||||
@@ -46,6 +122,17 @@ public:
|
||||
/** Set the input point array. */
|
||||
inline void setInputPointArray(osg::Vec3Array *points);
|
||||
|
||||
/** Add an input constraint loop.
|
||||
** the edges of the loop will constrain the triangulation.
|
||||
** if remove!=0, the internal triangles of the constraint will be removed;
|
||||
** the user may the replace the constraint line with an equivalent geometry.
|
||||
** GWM July 2005 */
|
||||
void addInputConstraint(DelaunayConstraint *dc) {
|
||||
constraint_lines.push_back(dc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** Get the const output normal array (optional). */
|
||||
inline const osg::Vec3Array *getOutputNormalArray() const;
|
||||
|
||||
@@ -63,15 +150,24 @@ public:
|
||||
|
||||
/** Get the generated primitive (call triangulate() first). */
|
||||
inline osg::DrawElementsUInt *getTriangles();
|
||||
|
||||
/** remove the triangles internal to the constraint loops.
|
||||
* (Line strips cannot remove any internal triangles). */
|
||||
void removeInternalTriangles(DelaunayConstraint *constraint);
|
||||
|
||||
protected:
|
||||
virtual ~DelaunayTriangulator();
|
||||
DelaunayTriangulator &operator=(const DelaunayTriangulator &) { return *this; }
|
||||
int getindex(const osg::Vec3 pt,const osg::Vec3Array *points);
|
||||
|
||||
private:
|
||||
osg::ref_ptr<osg::Vec3Array> points_;
|
||||
osg::ref_ptr<osg::Vec3Array> normals_;
|
||||
osg::ref_ptr<osg::DrawElementsUInt> prim_tris_;
|
||||
|
||||
// GWM these lines provide required edges in the triangulated shape.
|
||||
linelist constraint_lines;
|
||||
|
||||
};
|
||||
|
||||
// INLINE METHODS
|
||||
@@ -116,6 +212,18 @@ inline osg::DrawElementsUInt *DelaunayTriangulator::getTriangles()
|
||||
return prim_tris_.get();
|
||||
}
|
||||
|
||||
inline const osg::DrawElementsUInt *DelaunayConstraint::getTriangles() const
|
||||
{
|
||||
return prim_tris_.get();
|
||||
}
|
||||
|
||||
inline osg::DrawElementsUInt *DelaunayConstraint::getTriangles()
|
||||
{
|
||||
return prim_tris_.get();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user