creation
This commit is contained in:
parent
14a538a731
commit
e050ef0c2e
vcg/complex/vertexmesh
|
@ -0,0 +1,107 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __VCGLIB_VERTEXALLOCATOR
|
||||
#define __VCGLIB_VERTEXALLOCATOR
|
||||
|
||||
namespace vcg {
|
||||
namespace vertex {
|
||||
/** \addtogroup vertexmesh */
|
||||
/*@{*/
|
||||
/// Class to safely add vertexes and faces to a mesh updating all the involved pointers.
|
||||
/// It provides static memeber to add either vertex or faces to a edgemesh.
|
||||
template <class AllocateMeshType>
|
||||
class Allocator
|
||||
{
|
||||
|
||||
public:
|
||||
typedef AllocateMeshType MeshType;
|
||||
typedef typename MeshType::VertexType VertexType;
|
||||
typedef typename MeshType::VertexPointer VertexPointer;
|
||||
typedef typename MeshType::VertexIterator VertexIterator;
|
||||
|
||||
/** This class is used when allocating new vertexes and faces to update
|
||||
the pointers that can be changed when resizing the involved vectors of vertex or faces.
|
||||
It can also be used to prevent any update of the various mesh fields
|
||||
(e.g. in case you are building all the connections by hand as in a importer);
|
||||
*/
|
||||
template<class SimplexPointerType>
|
||||
class PointerUpdater
|
||||
{
|
||||
public:
|
||||
void Clear(){newBase=oldBase=newEnd=oldEnd=0;preventUpdateFlag=false;};
|
||||
void Update(SimplexPointerType &vp)
|
||||
{
|
||||
vp=newBase+(vp-oldBase);
|
||||
}
|
||||
bool NeedUpdate() {if(newBase!=oldBase && !preventUpdateFlag) return true; else return false;}
|
||||
|
||||
SimplexPointerType oldBase;
|
||||
SimplexPointerType newBase;
|
||||
SimplexPointerType newEnd;
|
||||
SimplexPointerType oldEnd;
|
||||
bool preventUpdateFlag; /// when true no update is considered necessary.
|
||||
};
|
||||
|
||||
|
||||
/** Function to safely add n vertices to a mesh.
|
||||
|
||||
@param m The mesh to be expanded
|
||||
@param n the number of vertexes to be added
|
||||
@param pu A PointerUpdater that stores the relocation that can be happened.
|
||||
*/
|
||||
static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointer> &pu)
|
||||
{
|
||||
VertexIterator last=m.vert.end();
|
||||
pu.Clear();
|
||||
if(m.vert.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element
|
||||
else pu.oldBase=&*m.vert.begin();
|
||||
|
||||
for(int i=0; i<n; ++i)
|
||||
{
|
||||
m.vert.push_back(MeshType::VertexType());
|
||||
m.vert.back().ClearFlags();
|
||||
}
|
||||
|
||||
m.vn+=n;
|
||||
return last;// iterator to the first added vertex
|
||||
}
|
||||
|
||||
static VertexIterator AddVertices(MeshType &m, int n)
|
||||
{
|
||||
PointerUpdater<VertexPointer> pu;
|
||||
return AddVertices(m, n,pu);
|
||||
}
|
||||
}; // end class
|
||||
/*@}*/
|
||||
} // End Namespace TriMesh
|
||||
} // End Namespace vcg
|
||||
|
||||
#endif
|
|
@ -0,0 +1,164 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#pragma warning( disable : 4804 )
|
||||
|
||||
#include <vcg/space/box3.h>
|
||||
#include <vcg/space/color4.h>
|
||||
|
||||
|
||||
/*
|
||||
People should subclass his vertex class from these one...
|
||||
*/
|
||||
|
||||
#ifndef __VCGLIB_VERTEXMESH
|
||||
#define __VCGLIB_VERTEXMESH
|
||||
|
||||
namespace vcg {
|
||||
namespace vertex {
|
||||
/** \addtogroup vertexmesh */
|
||||
/*@{*/
|
||||
|
||||
/** \class VertexMesh.
|
||||
This is class for definition of a mesh.
|
||||
@param VertContainerType (Template Parameter) Specifies the type of the vertices container any the vertex type.
|
||||
@param PointContainerType (Template Parameter) Specifies the type of the faces container any the face type.
|
||||
*/
|
||||
template < class VertContainerType >
|
||||
class VertexMesh{
|
||||
public:
|
||||
typedef VertContainerType VertexContainer;
|
||||
typedef typename VertContainerType::value_type VertexType;
|
||||
typedef typename VertContainerType::value_type::ScalarType ScalarType;
|
||||
typedef typename VertContainerType::value_type::CoordType CoordType;
|
||||
typedef typename VertContainerType::iterator VertexIterator;
|
||||
typedef typename VertContainerType::const_iterator ConstVertexIterator;
|
||||
typedef VertexType * VertexPointer;
|
||||
typedef const VertexType * ConstVertexPointer;
|
||||
typedef Box3<ScalarType> BoxType;
|
||||
|
||||
/// Set of vertices
|
||||
VertContainerType vert;
|
||||
/// Real number of vertices
|
||||
int vn;
|
||||
|
||||
/// Bounding box of the mesh
|
||||
Box3<ScalarType> bbox;
|
||||
|
||||
/// Global color
|
||||
private:
|
||||
Color4b c;
|
||||
public:
|
||||
|
||||
inline const Color4b & C() const
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
inline Color4b & C()
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
/// Default constructor
|
||||
VertexMesh()
|
||||
{
|
||||
vn = 0;
|
||||
imark = 0;
|
||||
}
|
||||
|
||||
inline int MemUsed() const
|
||||
{
|
||||
return sizeof(VertexMesh)*vert.size();
|
||||
}
|
||||
|
||||
inline int MemNeeded() const
|
||||
{
|
||||
return sizeof(VertexMesh)*vn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Function to destroy the mesh
|
||||
void Clear()
|
||||
{
|
||||
vert.clear();
|
||||
vn = 0;
|
||||
}
|
||||
|
||||
/// Reflection functions that speak about vertex and face properties.
|
||||
static bool HasPerVertexNormal() { return VertexType::HasNormal() ; }
|
||||
static bool HasPerVertexColor() { return VertexType::HasColor() ; }
|
||||
static bool HasPerVertexMark() { return VertexType::HasMark() ; }
|
||||
static bool HasPerVertexQuality() { return VertexType::HasQuality(); }
|
||||
static bool HasPerVertexTexture() { return VertexType::HasTexture(); }
|
||||
|
||||
/// Initialize the imark-system of the faces
|
||||
void InitPointIMark()
|
||||
{
|
||||
VertexIterator f;
|
||||
|
||||
for(f=vert.begin();f!=vert.end();++f)
|
||||
if( !(*f).IsDeleted() && (*f).IsR() && (*f).IsW() )
|
||||
(*f).InitIMark();
|
||||
}
|
||||
|
||||
/// Initialize the imark-system of the vertices
|
||||
void InitVertexIMark()
|
||||
{
|
||||
VertexIterator vi;
|
||||
|
||||
for(vi=vert.begin();vi!=vert.end();++vi)
|
||||
if( !(*vi).IsDeleted() && (*vi).IsRW() )
|
||||
(*vi).InitIMark();
|
||||
}
|
||||
|
||||
/// The incremental mark
|
||||
int imark;
|
||||
|
||||
/** Check if the vertex incremental mark matches the one of the mesh.
|
||||
*/
|
||||
inline bool IsMarked( ConstVertexPointer v ) const { return v->IMark() == imark; }
|
||||
/** Set the vertex incremental mark of the vertex to the one of the mesh.
|
||||
*/
|
||||
inline void Mark( ConstVertexPointer v ) const { v->IMark() = imark; }
|
||||
/// Unmark the mesh
|
||||
inline void UnMarkAll() { ++imark; }
|
||||
|
||||
}; // end class VertexMesh
|
||||
|
||||
/*@}*/
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/****************************************************************************
|
||||
* VCGLib o o *
|
||||
* Visual and Computer Graphics Library o o *
|
||||
* _ O _ *
|
||||
* Copyright(C) 2004 \/)\/ *
|
||||
* Visual Computing Lab /\/| *
|
||||
* ISTI - Italian National Research Council | *
|
||||
* \ *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||
* for more details. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
|
||||
****************************************************************************/
|
||||
#ifndef __VCG_POINT_UPDATE_BOUNDING
|
||||
#define __VCG_POINT_UPDATE_BOUNDING
|
||||
|
||||
namespace vcg {
|
||||
namespace vertex {
|
||||
|
||||
/** \addtogroup vertexmesh */
|
||||
/*@{*/
|
||||
|
||||
/// Management, updating and computation of per-vertex and per-face normals.
|
||||
/// This class is used to compute or update the normals that can be stored in the vertex or face component of a mesh.
|
||||
template <class ComputeMeshType>
|
||||
class UpdateBounding
|
||||
{
|
||||
|
||||
public:
|
||||
typedef ComputeMeshType MeshType;
|
||||
typedef typename MeshType::VertexType VertexType;
|
||||
typedef typename MeshType::VertexPointer VertexPointer;
|
||||
typedef typename MeshType::VertexIterator VertexIterator;
|
||||
|
||||
/// Calculates the vertex normal (if stored in the current face type)
|
||||
static void Box(ComputeMeshType &m)
|
||||
{
|
||||
m.bbox.SetNull();
|
||||
VertexIterator vi;
|
||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||
if( !(*vi).IsD() ) m.bbox.Add((*vi).P());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}; // end class
|
||||
|
||||
} // End namespace
|
||||
} // End namespace
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue