Renamed a symbol that caused ambiguity (VertexInfo -> vertexClipInfo) added functor and function for box clipping
This commit is contained in:
parent
168953b768
commit
beb996e9c9
|
|
@ -32,13 +32,72 @@ $Log: not supported by cvs2svn $
|
||||||
#define __VCGLIB_TRI_CLIP
|
#define __VCGLIB_TRI_CLIP
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <hash_map>
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifndef __MINGW32__
|
||||||
|
#include <hash_map>
|
||||||
|
#define STDEXT stdext
|
||||||
|
#else
|
||||||
|
#include <ext/hash_map>
|
||||||
|
#define STDEXT __gnu_cxx
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#include <ext/hash_map>
|
||||||
|
#define STDEXT __gnu_cxx
|
||||||
|
#endif
|
||||||
namespace vcg
|
namespace vcg
|
||||||
{
|
{
|
||||||
namespace tri
|
namespace tri
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template <typename MESH_TYPE>
|
||||||
|
class GenericVertexInterpolator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename MESH_TYPE::VertexType VertexType;
|
||||||
|
typedef GenericVertexInterpolator<MESH_TYPE> ClassType;
|
||||||
|
typedef typename VertexType::CoordType CoordType;
|
||||||
|
typedef typename CoordType::ScalarType ScalarType;
|
||||||
|
GenericVertexInterpolator(MESH_TYPE &_m) : m(_m) {}
|
||||||
|
private:
|
||||||
|
MESH_TYPE &m;
|
||||||
|
public:
|
||||||
|
inline void operator () (const VertexType & v0, const VertexType & v1, const VertexType & v2, const ScalarType & a, const ScalarType & b, VertexType & r) const
|
||||||
|
{
|
||||||
|
// position
|
||||||
|
r.P() = v0.P() + (v1.P() - v0.P()) * a + (v2.P() - v0.P()) * b;
|
||||||
|
|
||||||
|
// normal
|
||||||
|
if (tri::HasPerVertexNormal(m))
|
||||||
|
{
|
||||||
|
r.N() = v0.cN() + (v1.cN() - v0.cN()) * a + (v2.cN() - v0.cN()) * b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// color
|
||||||
|
if (tri::HasPerVertexColor(m))
|
||||||
|
{
|
||||||
|
vcg::Point4<ScalarType> vc[3];
|
||||||
|
vc[0].Import(v0.cC());
|
||||||
|
vc[1].Import(v1.cC());
|
||||||
|
vc[2].Import(v2.cC());
|
||||||
|
const vcg::Point4<ScalarType> rc = (vc[0] + (vc[1] - vc[0]) * a + (vc[2] - vc[0]) * b);
|
||||||
|
r.C()[0] = (typename vcg::Color4b::ScalarType)(rc[0]);
|
||||||
|
r.C()[1] = (typename vcg::Color4b::ScalarType)(rc[1]);
|
||||||
|
r.C()[2] = (typename vcg::Color4b::ScalarType)(rc[2]);
|
||||||
|
r.C()[3] = (typename vcg::Color4b::ScalarType)(rc[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// texcoord
|
||||||
|
if (tri::HasPerVertexTexCoord(m))
|
||||||
|
{
|
||||||
|
const short nt = 1; //typename VertexType::TextureType::N();
|
||||||
|
for (short i=0; i<nt; ++i)
|
||||||
|
{
|
||||||
|
r.T().t(i) = v0.cT().t(i) + (v1.cT().t(i) - v0.cT().t(i)) * a + (v2.cT().t(i) - v0.cT().t(i)) * b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
template <typename TRIMESHTYPE>
|
template <typename TRIMESHTYPE>
|
||||||
class TriMeshClipper
|
class TriMeshClipper
|
||||||
{
|
{
|
||||||
|
|
@ -71,39 +130,18 @@ public:
|
||||||
r.N() = v0.N() + a * (v1.N() - v0.N()) + b * (v2.N() - v0.N()); // interpolate normal
|
r.N() = v0.N() + a * (v1.N() - v0.N()) + b * (v2.N() - v0.N()); // interpolate normal
|
||||||
... // interpolate other vertex attributes
|
... // interpolate other vertex attributes
|
||||||
*/
|
*/
|
||||||
|
template <class ScalarType>
|
||||||
template <typename VERTEXINTEPOLATOR>
|
class VertexClipInfo
|
||||||
static inline void Box(const Box3<ScalarType> & b, VERTEXINTEPOLATOR & vInterp, TriMeshType & m)
|
|
||||||
{
|
|
||||||
std::vector<unsigned int> facesToDelete;
|
|
||||||
ClassType::Box(b, vInterp, m, facesToDelete);
|
|
||||||
for (size_t i=0; i<facesToDelete.size(); ++i)
|
|
||||||
{
|
|
||||||
m.face[facesToDelete[i]].SetD();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename VERTEXINTEPOLATOR, typename FACEINDEXCONTAINER>
|
|
||||||
static inline void Box(const Box3<ScalarType> & b, VERTEXINTEPOLATOR & vInterp, TriMeshType & m, FACEINDEXCONTAINER & facesToDelete)
|
|
||||||
{
|
|
||||||
if (m.fn <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
class VertexInfo
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef VertexInfo ClassType;
|
// typedef VertexClipInfo ClassType;
|
||||||
|
|
||||||
ScalarType fU;
|
ScalarType fU;
|
||||||
ScalarType fV;
|
ScalarType fV;
|
||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
unsigned int tref;
|
unsigned int tref;
|
||||||
};
|
};
|
||||||
|
typedef typename std::vector< VertexClipInfo<ScalarType> > VertexClipInfoVec;
|
||||||
typedef std::vector<VertexInfo> VertexInfoVec;
|
|
||||||
|
|
||||||
class TriangleInfo
|
class TriangleInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -122,6 +160,17 @@ public:
|
||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename VERTEXINTEPOLATOR>
|
||||||
|
static inline void Box(const Box3<ScalarType> & b, VERTEXINTEPOLATOR & vInterp, TriMeshType & m)
|
||||||
|
{
|
||||||
|
std::vector<unsigned int> facesToDelete;
|
||||||
|
ClassType::Box(b, vInterp, m, facesToDelete);
|
||||||
|
for (size_t i=0; i<facesToDelete.size(); ++i)
|
||||||
|
{
|
||||||
|
m.face[facesToDelete[i]].SetD();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class EdgeIntersections
|
class EdgeIntersections
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -134,18 +183,26 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef stdext::hash_map<unsigned int, EdgeIntersections> UIntHMap;
|
typedef STDEXT::hash_map<unsigned int, EdgeIntersections> UIntHMap;
|
||||||
typedef typename UIntHMap::iterator UIntHMap_i;
|
typedef typename UIntHMap::iterator UIntHMap_i;
|
||||||
typedef typename UIntHMap::value_type UIntHMap_v;
|
typedef typename UIntHMap::value_type UIntHMap_v;
|
||||||
|
|
||||||
typedef stdext::hash_map<unsigned int, UIntHMap> EdgeMap;
|
typedef STDEXT::hash_map<unsigned int, UIntHMap> EdgeMap;
|
||||||
typedef typename EdgeMap::iterator EdgeMap_i;
|
typedef typename EdgeMap::iterator EdgeMap_i;
|
||||||
typedef typename EdgeMap::value_type EdgeMap_v;
|
typedef typename EdgeMap::value_type EdgeMap_v;
|
||||||
|
|
||||||
typedef typename TriMeshType::FaceIterator FaceIterator;
|
typedef typename TriMeshType::FaceIterator FaceIterator;
|
||||||
|
|
||||||
|
template <typename VERTEXINTEPOLATOR, typename FACEINDEXCONTAINER>
|
||||||
|
static inline void Box(const Box3<ScalarType> & b, VERTEXINTEPOLATOR & vInterp, TriMeshType & m, FACEINDEXCONTAINER & facesToDelete)
|
||||||
|
{
|
||||||
|
if (m.fn <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
EdgeMap edges;
|
EdgeMap edges;
|
||||||
VertexInfoVec vInfos;
|
VertexClipInfoVec vInfos;
|
||||||
TriangleInfoVec tInfos;
|
TriangleInfoVec tInfos;
|
||||||
|
|
||||||
CoordType vTriangle[4];
|
CoordType vTriangle[4];
|
||||||
|
|
@ -250,7 +307,7 @@ public:
|
||||||
|
|
||||||
size_t vBegin = vInfos.size();
|
size_t vBegin = vInfos.size();
|
||||||
|
|
||||||
VertexInfo vnfo;
|
VertexClipInfo<ScalarType> vnfo;
|
||||||
TriangleInfo tnfo;
|
TriangleInfo tnfo;
|
||||||
|
|
||||||
unsigned int vmin[3];
|
unsigned int vmin[3];
|
||||||
|
|
@ -476,10 +533,10 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
class VertexInfo
|
class VertexClipInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef VertexInfo ClassType;
|
typedef VertexClipInfo ClassType;
|
||||||
|
|
||||||
ScalarType fU;
|
ScalarType fU;
|
||||||
ScalarType fV;
|
ScalarType fV;
|
||||||
|
|
@ -487,7 +544,7 @@ public:
|
||||||
unsigned int tref;
|
unsigned int tref;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<VertexInfo> VertexInfoVec;
|
typedef std::vector<VertexClipInfo> VertexClipInfoVec;
|
||||||
|
|
||||||
class TriangleInfo
|
class TriangleInfo
|
||||||
{
|
{
|
||||||
|
|
@ -519,22 +576,22 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef stdext::hash_map<unsigned int, EdgeIntersections> UIntHMap;
|
typedef STDEXT::hash_map<unsigned int, EdgeIntersections> UIntHMap;
|
||||||
typedef typename UIntHMap::iterator UIntHMap_i;
|
typedef typename UIntHMap::iterator UIntHMap_i;
|
||||||
typedef typename UIntHMap::value_type UIntHMap_v;
|
typedef typename UIntHMap::value_type UIntHMap_v;
|
||||||
|
|
||||||
typedef stdext::hash_map<unsigned int, UIntHMap> EdgeMap;
|
typedef STDEXT::hash_map<unsigned int, UIntHMap> EdgeMap;
|
||||||
typedef typename EdgeMap::iterator EdgeMap_i;
|
typedef typename EdgeMap::iterator EdgeMap_i;
|
||||||
typedef typename EdgeMap::value_type EdgeMap_v;
|
typedef typename EdgeMap::value_type EdgeMap_v;
|
||||||
|
|
||||||
typedef stdext::hash_map<unsigned int, unsigned int> UIHMap;
|
typedef STDEXT::hash_map<unsigned int, unsigned int> UIHMap;
|
||||||
typedef typename UIHMap::iterator UIHMap_i;
|
typedef typename UIHMap::iterator UIHMap_i;
|
||||||
|
|
||||||
typedef typename TriMeshType::ConstFaceIterator ConstFaceIterator;
|
typedef typename TriMeshType::ConstFaceIterator ConstFaceIterator;
|
||||||
|
|
||||||
UIHMap origVertsMap;
|
UIHMap origVertsMap;
|
||||||
EdgeMap edges;
|
EdgeMap edges;
|
||||||
VertexInfoVec vInfos;
|
VertexClipInfoVec vInfos;
|
||||||
TriangleInfoVec tInfos;
|
TriangleInfoVec tInfos;
|
||||||
|
|
||||||
CoordType vTriangle[4];
|
CoordType vTriangle[4];
|
||||||
|
|
@ -580,7 +637,7 @@ public:
|
||||||
if ((cc[0] | cc[1] | cc[2]) == 0)
|
if ((cc[0] | cc[1] | cc[2]) == 0)
|
||||||
{
|
{
|
||||||
TriangleInfo tnfo;
|
TriangleInfo tnfo;
|
||||||
VertexInfo vnfo;
|
VertexClipInfo vnfo;
|
||||||
|
|
||||||
tnfo.idx = tIdx++;
|
tnfo.idx = tIdx++;
|
||||||
|
|
||||||
|
|
@ -660,7 +717,7 @@ public:
|
||||||
|
|
||||||
size_t vBegin = vInfos.size();
|
size_t vBegin = vInfos.size();
|
||||||
|
|
||||||
VertexInfo vnfo;
|
VertexClipInfo vnfo;
|
||||||
TriangleInfo tnfo;
|
TriangleInfo tnfo;
|
||||||
|
|
||||||
unsigned int vmin[3];
|
unsigned int vmin[3];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue