minimal ply tetra importer and tetragl (immediate mode)
This commit is contained in:
parent
fb0684974a
commit
85f3a5fad5
|
@ -39,7 +39,7 @@ class GLW {
|
|||
public:
|
||||
enum DrawMode {DMNone, DMSmallTetra,DMFlat,DMWire, DMHidden,DMTransparent,DMFlatWire} ;
|
||||
enum NormalMode{NMFlat,NMSmooth, NMUser, NMPerMesh};
|
||||
enum ColorMode {CMNone, CMPerMesh,CMUser,CMPerTetraF,CMPerVertexF,CMPerVertex};
|
||||
enum ColorMode {CMNone, CMPerMesh,CMUser,CMPerTetra,CMPerVertexF,CMPerVertex};
|
||||
enum Hint {HShrinkFactor};
|
||||
};
|
||||
|
||||
|
@ -112,6 +112,10 @@ public:
|
|||
{
|
||||
P=p;
|
||||
}
|
||||
bool IsClipped(Point3x p)
|
||||
{
|
||||
return D.V(0) * p.X() + D.V(1) * p.Y() + D.V(2) * p.Z() - vcg::Norm(P) < 0;
|
||||
}
|
||||
|
||||
void GlClip()
|
||||
{
|
||||
|
@ -148,7 +152,6 @@ public:
|
|||
|
||||
glPopAttrib();
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
|
||||
void Transform(vcg::Matrix44<float> Tr)
|
||||
|
@ -177,7 +180,7 @@ public:
|
|||
ClipPlane section;
|
||||
|
||||
private:
|
||||
ScalarType shrink_factor;
|
||||
ScalarType shrink_factor = 0.95f;
|
||||
|
||||
|
||||
public:
|
||||
|
@ -199,15 +202,7 @@ public:
|
|||
section.active=false;
|
||||
}
|
||||
|
||||
typedef Color4b (*color_func_vertex)(VertexType&v);
|
||||
color_func_vertex color_vertex;
|
||||
|
||||
typedef Color4b (*color_func_tetra)(TetraType&v);
|
||||
color_func_tetra color_tetra;
|
||||
|
||||
|
||||
template <DrawMode dm,NormalMode nm,ColorMode cm >
|
||||
|
||||
void Draw(){
|
||||
switch (dm){
|
||||
case DMNone: break;
|
||||
|
@ -223,19 +218,15 @@ public:
|
|||
private:
|
||||
template <ColorMode cm >
|
||||
void _DrawSmallTetra(){
|
||||
Point3x p[4],br;
|
||||
typename CONT_TETRA::iterator it;
|
||||
glPushAttrib(0xffffffff);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_NORMALIZE);
|
||||
glPolygonMode(GL_FRONT,GL_FILL);
|
||||
if (section.active)
|
||||
{
|
||||
section.GlClip();
|
||||
section.GlDraw();
|
||||
}
|
||||
|
||||
// glPushAttrib(0xffff);
|
||||
// glEnable(GL_COLOR_MATERIAL);
|
||||
// glEnable(GL_NORMALIZE);
|
||||
// glPolygonMode(GL_FRONT, GL_FILL);
|
||||
// glLight(GL_LIGHT0, GL_DIFFUSE, vcg::Color4b::White);
|
||||
// glEnable(GL_LIGHT0);
|
||||
// glEnable(GL_LIGHTING);
|
||||
/*glBegin(GL_TRIANGLES);*/
|
||||
for( it = tetra->begin(); it != tetra->end(); ++it)
|
||||
if((!it->IsD())&&(!(it->IsS()))) //draw as normal
|
||||
|
@ -248,7 +239,12 @@ template <ColorMode cm >
|
|||
_DrawSelectedTetra(*it);
|
||||
}
|
||||
//glEnd();
|
||||
glPopAttrib();
|
||||
// glPopAttrib();
|
||||
if (section.active)
|
||||
{
|
||||
// section.GlClip();
|
||||
section.GlDraw();
|
||||
}
|
||||
}
|
||||
|
||||
template <NormalMode nm,ColorMode cm >
|
||||
|
@ -280,6 +276,7 @@ void _DrawSurface(){
|
|||
}
|
||||
else
|
||||
{
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_NORMALIZE);
|
||||
glPolygonMode(GL_FRONT,GL_FILL);
|
||||
|
@ -356,14 +353,16 @@ void _ChooseColorTetra(TetraType &t)
|
|||
else
|
||||
glColor3d(0.8f,0.8f,0.8f);
|
||||
}
|
||||
else
|
||||
if(cm == CMPerTetraF)
|
||||
{
|
||||
Color4b c;
|
||||
c = color_tetra(t);
|
||||
GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3];
|
||||
glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic);
|
||||
}
|
||||
if (cm == CMPerTetra)
|
||||
vcg::glColor(t.C());
|
||||
// else
|
||||
// if(cm == CMPerTetraF)
|
||||
// {
|
||||
// Color4b c;
|
||||
// c = color_tetra(t);
|
||||
// GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3];
|
||||
// glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic);
|
||||
// }
|
||||
}
|
||||
|
||||
template <ColorMode cm >
|
||||
|
@ -371,16 +370,16 @@ void _ChooseColorVertex(VertexType &v)
|
|||
{
|
||||
if (cm!=CMNone)
|
||||
{
|
||||
if(cm == CMPerVertexF)
|
||||
{
|
||||
Color4b c;
|
||||
c = color_vertex(v);
|
||||
GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3];
|
||||
glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic);
|
||||
}
|
||||
else
|
||||
// if(cm == CMPerVertexF)
|
||||
// {
|
||||
// Color4b c;
|
||||
// c = color_vertex(v);
|
||||
// GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3];
|
||||
// glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic);
|
||||
// }
|
||||
// else
|
||||
if(cm == CMPerVertex)
|
||||
glColor3f(v.C()[0],v.C()[1],v.C()[2]);
|
||||
vcg::glColor(v.C());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,10 +408,10 @@ template <ColorMode cm >
|
|||
void _DrawFace(TetraType &t,int face)
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
glNormal(t.N(face));
|
||||
VertexType *v0=t.V(Tetra::VofF(face,0));
|
||||
VertexType *v1=t.V(Tetra::VofF(face,1));
|
||||
VertexType *v2=t.V(Tetra::VofF(face,2));
|
||||
glNormal(vcg::Normal(v0->P(), v1->P(), v2->P()).normalized());
|
||||
_ChooseColorVertex<cm>(*v0);
|
||||
glVertex(v0->P());
|
||||
_ChooseColorVertex<cm>(*v1);
|
||||
|
@ -425,24 +424,39 @@ glBegin(GL_TRIANGLES);
|
|||
template < ColorMode cm >
|
||||
void _DrawSmallTetra(TetraType &t)
|
||||
{
|
||||
Tetra3<ScalarType> T=Tetra3<ScalarType>();
|
||||
T.P0(0)=t.V(0)->cP();
|
||||
T.P1(0)=t.V(1)->cP();
|
||||
T.P2(0)=t.V(2)->cP();
|
||||
T.P3(0)=t.V(3)->cP();
|
||||
Point3x p[4], br;
|
||||
br=T.ComputeBarycenter();
|
||||
br = Tetra::Barycenter(t);
|
||||
if (section.IsClipped(br))
|
||||
return;
|
||||
bool border = false;
|
||||
bool clipBorder = false;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
border = border || t.IsB(i);
|
||||
|
||||
Point3x br1 = Tetra::Barycenter(*t.TTp(i));
|
||||
clipBorder = clipBorder || section.IsClipped(br1);
|
||||
}
|
||||
|
||||
if (!border && !clipBorder)
|
||||
return;
|
||||
|
||||
for(int i = 0; i < 4; ++i)
|
||||
p[i] = t.V(i)->P() * shrink_factor + br * (1 - shrink_factor);
|
||||
|
||||
|
||||
_ChooseColorTetra<cm>(t);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
glNormal(t.N(i));
|
||||
VertexType *v0=t.V(Tetra::VofF(i,0));
|
||||
VertexType *v1=t.V(Tetra::VofF(i,1));
|
||||
VertexType *v2=t.V(Tetra::VofF(i,2));
|
||||
|
||||
|
||||
glNormal(vcg::Normal(v0->P(), v1->P(), v2->P()).normalized());
|
||||
|
||||
_ChooseColorVertex<cm>(*v0);
|
||||
glVertex(p[Tetra::VofF(i,0)]);
|
||||
_ChooseColorVertex<cm>(*v1);
|
||||
|
@ -452,8 +466,6 @@ void _DrawSmallTetra(TetraType &t)
|
|||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // end namespace tetra
|
||||
|
|
|
@ -85,6 +85,7 @@ struct LoadPly_TetraAux
|
|||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
|
||||
unsigned char data[MAX_USER_DATA];
|
||||
};
|
||||
|
@ -106,6 +107,7 @@ struct LoadPly_VertAux
|
|||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
unsigned char data[MAX_USER_DATA];
|
||||
};
|
||||
|
||||
|
@ -140,15 +142,15 @@ struct LoadPly_VertAux
|
|||
static const PropDescriptor &VertDesc(int i)
|
||||
{
|
||||
const static PropDescriptor pv[9]={
|
||||
{"vertex", "x", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p[0]),0,0,0,0,0},
|
||||
{"vertex", "y", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p[1]),0,0,0,0,0},
|
||||
{"vertex", "z", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p[2]),0,0,0,0,0},
|
||||
{"vertex", "x", ply::T_FLOAT, PlyType<ScalarType>(), offsetof(LoadPly_VertAux<ScalarType>,p),0,0,0,0,0},
|
||||
{"vertex", "y", ply::T_FLOAT, PlyType<ScalarType>(), offsetof(LoadPly_VertAux<ScalarType>,p) + sizeof(ScalarType),0,0,0,0,0},
|
||||
{"vertex", "z", ply::T_FLOAT, PlyType<ScalarType>(), offsetof(LoadPly_VertAux<ScalarType>,p) + 2 * sizeof(ScalarType),0,0,0,0,0},
|
||||
{"vertex", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_VertAux<ScalarType>,flags),0,0,0,0,0},
|
||||
{"vertex", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux<ScalarType>,q),0,0,0,0,0},
|
||||
{"vertex", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,r),0,0,0,0,0},
|
||||
{"vertex", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,g),0,0,0,0,0},
|
||||
{"vertex", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,b),0,0,0,0,0},
|
||||
{"vertex", "confidence",ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux<ScalarType>,q),0,0,0,0,0},
|
||||
{"vertex", "alpha" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,a),0,0,0,0,0},
|
||||
};
|
||||
return pv[i];
|
||||
}
|
||||
|
@ -167,51 +169,13 @@ static const PropDescriptor &TetraDesc(int i)
|
|||
{"tetra", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,r), 0,0,0,0,0},
|
||||
{"tetra", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,g), 0,0,0,0,0},
|
||||
{"tetra", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,b), 0,0,0,0,0},
|
||||
{"tetra", "vertex_index", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,v), 1,0,ply::T_UCHAR,ply::T_CHAR,offsetof(LoadPly_TetraAux,size) },
|
||||
{"tetra", "alpha" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,a), 0,0,0,0,0},
|
||||
|
||||
};
|
||||
return qf[i];
|
||||
}
|
||||
//static const PropDescriptor &TristripDesc(int i)
|
||||
//{
|
||||
// const static PropDescriptor qf[1]=
|
||||
// {
|
||||
// {"tristrips","vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_TristripAux,v), 1,1,ply::T_INT,ply::T_INT,offsetof(LoadPly_TristripAux,size) },
|
||||
// };
|
||||
// return qf[i];
|
||||
//}
|
||||
|
||||
|
||||
//static const PropDescriptor &CameraDesc(int i)
|
||||
//{
|
||||
// const static PropDescriptor cad[23] =
|
||||
// {
|
||||
// {"camera","view_px",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_px),0,0,0,0,0},
|
||||
// {"camera","view_py",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_py),0,0,0,0,0},
|
||||
// {"camera","view_pz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_pz),0,0,0,0,0},
|
||||
// {"camera","x_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisx),0,0,0,0,0},
|
||||
// {"camera","x_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisy),0,0,0,0,0},
|
||||
// {"camera","x_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisz),0,0,0,0,0},
|
||||
// {"camera","y_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisx),0,0,0,0,0},
|
||||
// {"camera","y_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisy),0,0,0,0,0},
|
||||
// {"camera","y_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisz),0,0,0,0,0},
|
||||
// {"camera","z_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisx),0,0,0,0,0},
|
||||
// {"camera","z_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisy),0,0,0,0,0},
|
||||
// {"camera","z_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisz),0,0,0,0,0},
|
||||
// {"camera","focal" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,focal ),0,0,0,0,0},
|
||||
// {"camera","scalex" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scalex ),0,0,0,0,0},
|
||||
// {"camera","scaley" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scaley ),0,0,0,0,0},
|
||||
// {"camera","centerx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centerx),0,0,0,0,0},
|
||||
// {"camera","centery",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centery),0,0,0,0,0},
|
||||
// {"camera","viewportx",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewportx),0,0,0,0,0},
|
||||
// {"camera","viewporty",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewporty),0,0,0,0,0},
|
||||
// {"camera","k1" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k1 ),0,0,0,0,0},
|
||||
// {"camera","k2" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k2 ),0,0,0,0,0},
|
||||
// {"camera","k3" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k3 ),0,0,0,0,0},
|
||||
// {"camera","k4" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k4 ),0,0,0,0,0}
|
||||
// };
|
||||
// return cad[i];
|
||||
//}
|
||||
|
||||
|
||||
/// Standard call for reading a mesh
|
||||
static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0)
|
||||
|
@ -236,8 +200,8 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
{
|
||||
assert(filename!=0);
|
||||
vector<VertexPointer> index;
|
||||
|
||||
LoadPly_TetraAux fa;
|
||||
// LoadPly_TristripAux tsa;
|
||||
LoadPly_VertAux<ScalarType> va;
|
||||
|
||||
pi.mask = 0;
|
||||
|
@ -250,91 +214,63 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
vcg::ply::PlyFile pf;
|
||||
|
||||
// Open the file and parse the header
|
||||
std::cerr << "Parsing the header.." << std::endl;
|
||||
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)== -1 )
|
||||
{
|
||||
pi.status = pf.GetError();
|
||||
return -1;
|
||||
}
|
||||
std::cerr << "Parsed the header.." << std::endl;
|
||||
pi.header = pf.GetHeader();
|
||||
|
||||
// Descrittori della camera
|
||||
{ // Check that all the camera properties are present.
|
||||
/* bool found = true;
|
||||
for(int i=0;i<23;++i)
|
||||
{
|
||||
if( pf.AddToRead(CameraDesc(i))==-1 ) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found) pi.mask |= ply::PLYMask::PM_CAMERA;*/
|
||||
}
|
||||
|
||||
// Descrittori dati standard (vertex coord e faces)
|
||||
if( pf.AddToRead(VertDesc(0)) == -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||
if( pf.AddToRead(VertDesc(1)) == -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||
if( pf.AddToRead(VertDesc(2)) == -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||
if( pf.AddToRead(TetraDesc(0))== -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||
|
||||
|
||||
// Se fallisce si prova anche la sintassi di rapidform con index al posto di indices
|
||||
// if( pf.AddToRead(TetraDesc(9))==-1 )
|
||||
// if(pf.AddToRead(TristripDesc(0))==-1) // Se fallisce tutto si prova a vedere se ci sono tristrip alla levoy.
|
||||
// { pi.status = PlyInfo::E_NO_FACE; return -1; }
|
||||
|
||||
// Descrittori facoltativi dei flags
|
||||
if( pf.AddToRead(VertDesc(3))!=-1 )
|
||||
pi.mask |= ply::PLYMask::PM_VERTFLAGS;
|
||||
|
||||
pi.mask |= vcg::tetra::io::Mask::IOM_VERTFLAGS;
|
||||
if( VertexType::HasQuality() )
|
||||
{
|
||||
if( pf.AddToRead(VertDesc(4))!=-1 ||
|
||||
pf.AddToRead(VertDesc(8))!=-1 )
|
||||
pi.mask |= ply::PLYMask::PM_VERTQUALITY;
|
||||
pf.AddToRead(VertDesc(9))!=-1 )
|
||||
pi.mask |= vcg::tetra::io::Mask::IOM_VERTQUALITY;
|
||||
}
|
||||
|
||||
if( VertexType::HasColor() )
|
||||
{
|
||||
if( pf.AddToRead(VertDesc(5))!=-1 )
|
||||
{
|
||||
pf.AddToRead(VertDesc(6));
|
||||
pf.AddToRead(VertDesc(7));
|
||||
pi.mask |= ply::PLYMask::PM_VERTCOLOR;
|
||||
}
|
||||
}
|
||||
pf.AddToRead(VertDesc(8));
|
||||
|
||||
pi.mask |= vcg::tetra::io::Mask::IOM_VERTCOLOR;
|
||||
}
|
||||
}
|
||||
// se ci sono i flag per vertice ci devono essere anche i flag per faccia
|
||||
if( pf.AddToRead(TetraDesc(1))!=-1 )
|
||||
pi.mask |= ply::PLYMask::PM_TETRAFLAGS;
|
||||
|
||||
if( TetraType::HasTetraQuality())
|
||||
pi.mask |= vcg::tetra::io::Mask::IOM_TETRAFLAGS;
|
||||
if( TetraType::HasQuality())
|
||||
{
|
||||
if( pf.AddToRead(TetraDesc(2))!=-1 )
|
||||
pi.mask |= ply::PLYMask::PM_TETRAQUALITY;
|
||||
pi.mask |= vcg::tetra::io::Mask::IOM_TETRAQUALITY;
|
||||
}
|
||||
|
||||
if( TetraType::HasTetraColor() )
|
||||
if( TetraType::HasColor() )
|
||||
{
|
||||
if( pf.AddToRead(TetraDesc(6))!=-1 )
|
||||
{
|
||||
pf.AddToRead(TetraDesc(7));
|
||||
pf.AddToRead(TetraDesc(8));
|
||||
pi.mask |= ply::PLYMask::PM_TETRACOLOR;
|
||||
pf.AddToRead(TetraDesc(9));
|
||||
pi.mask |= vcg::tetra::io::Mask::IOM_TETRACOLOR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if( FaceType::HasWedgeColor() || FaceType::HasFaceColor() || VertexType::HasColor())
|
||||
//{
|
||||
// if( pf.AddToRead(TetraDesc(4))!=-1 )
|
||||
// {
|
||||
// pi.mask |= ply::PLYMask::PM_WEDGCOLOR;
|
||||
// }
|
||||
//}
|
||||
|
||||
// Descrittori definiti dall'utente,
|
||||
vector<PropDescriptor> VPV(pi.vdn); // property descriptor relative al tipo LoadPly_VertexAux
|
||||
vector<PropDescriptor> FPV(pi.fdn); // property descriptor relative al tipo LoadPly_FaceAux
|
||||
|
||||
if(pi.vdn>0){
|
||||
// Compute the total size needed to load additional per vertex data.
|
||||
size_t totsz=0;
|
||||
|
@ -364,7 +300,6 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
/* Main Reading Loop */
|
||||
/**************************************************************/
|
||||
|
@ -373,46 +308,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
{
|
||||
int n = pf.ElemNumber(i);
|
||||
|
||||
if( !strcmp( pf.ElemName(i),"camera" ) )
|
||||
{
|
||||
pf.SetCurElement(i);
|
||||
|
||||
// LoadPly_Camera ca;
|
||||
|
||||
for(int j=0;j<n;++j)
|
||||
{
|
||||
/* if( pf.Read( (void *)&(ca) )==-1 )
|
||||
{
|
||||
pi.status = PlyInfo::E_SHORTFILE;
|
||||
return -1;
|
||||
} */
|
||||
//camera.valid = true;
|
||||
//camera.view_p[0] = ca.view_px;
|
||||
//camera.view_p[1] = ca.view_py;
|
||||
//camera.view_p[2] = ca.view_pz;
|
||||
//camera.x_axis[0] = ca.x_axisx;
|
||||
//camera.x_axis[1] = ca.x_axisy;
|
||||
//camera.x_axis[2] = ca.x_axisz;
|
||||
//camera.y_axis[0] = ca.y_axisx;
|
||||
//camera.y_axis[1] = ca.y_axisy;
|
||||
//camera.y_axis[2] = ca.y_axisz;
|
||||
//camera.z_axis[0] = ca.z_axisx;
|
||||
//camera.z_axis[1] = ca.z_axisy;
|
||||
//camera.z_axis[2] = ca.z_axisz;
|
||||
//camera.f = ca.focal;
|
||||
//camera.s[0] = ca.scalex;
|
||||
//camera.s[1] = ca.scaley;
|
||||
//camera.c[0] = ca.centerx;
|
||||
//camera.c[1] = ca.centery;
|
||||
//camera.viewport[0] = ca.viewportx;
|
||||
//camera.viewport[1] = ca.viewporty;
|
||||
//camera.k[0] = ca.k1;
|
||||
//camera.k[1] = ca.k2;
|
||||
//camera.k[2] = ca.k3;
|
||||
//camera.k[3] = ca.k4;
|
||||
}
|
||||
}
|
||||
else if( !strcmp( pf.ElemName(i),"vertex" ) )
|
||||
if( !strcmp( pf.ElemName(i),"vertex" ) )
|
||||
{
|
||||
int j;
|
||||
|
||||
|
@ -432,18 +328,18 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
(*vi).P()[1] = va.p[1];
|
||||
(*vi).P()[2] = va.p[2];
|
||||
|
||||
if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
|
||||
if( pi.mask & vcg::tetra::io::Mask::IOM_VERTFLAGS )
|
||||
(*vi).Flags() = va.flags;
|
||||
|
||||
if( pi.mask & ply::PLYMask::PM_VERTQUALITY )
|
||||
if( pi.mask & vcg::tetra::io::Mask::IOM_VERTQUALITY )
|
||||
(*vi).Q() = va.q;
|
||||
|
||||
if( pi.mask & ply::PLYMask::PM_VERTCOLOR )
|
||||
if( pi.mask & vcg::tetra::io::Mask::IOM_VERTCOLOR )
|
||||
{
|
||||
|
||||
(*vi).C()[0] = va.r;
|
||||
(*vi).C()[1] = va.g;
|
||||
(*vi).C()[2] = va.b;
|
||||
(*vi).C()[3] = 255;
|
||||
(*vi).C()[3] = va.a;
|
||||
}
|
||||
|
||||
|
||||
|
@ -462,7 +358,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
{
|
||||
int j;
|
||||
int k;
|
||||
TetraIterator fi=Allocator<OpenMeshType>::AddTetra(m,n);
|
||||
TetraIterator ti = Allocator<OpenMeshType>::AddTetras(m, n);
|
||||
pf.SetCurElement(i);
|
||||
|
||||
for(j=0;j<n;++j)
|
||||
|
@ -488,81 +384,34 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
||||
return -1;
|
||||
}
|
||||
(*fi).V(k) = index[ fa.v[k] ];
|
||||
(*ti).V(k) = index[ fa.v[k] ];
|
||||
}
|
||||
|
||||
if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
|
||||
if( pi.mask & vcg::tetra::io::Mask::IOM_TETRAFLAGS )
|
||||
{
|
||||
(*fi).Flags() = fa.flags;
|
||||
(*ti).Flags() = fa.flags;
|
||||
}
|
||||
|
||||
if( pi.mask & ply::PLYMask::PM_TETRAQUALITY )
|
||||
if( pi.mask & vcg::tetra::io::Mask::IOM_TETRAQUALITY )
|
||||
{
|
||||
(*fi).Q() = fa.q;
|
||||
(*ti).Q() = fa.q;
|
||||
}
|
||||
|
||||
if( pi.mask & ply::PLYMask::PM_TETRACOLOR )
|
||||
if( pi.mask & vcg::tetra::io::Mask::IOM_TETRACOLOR )
|
||||
{
|
||||
(*fi).C()[0] = fa.r;
|
||||
(*fi).C()[1] = fa.g;
|
||||
(*fi).C()[2] = fa.b;
|
||||
(*fi).C()[3] = 255;
|
||||
}
|
||||
|
||||
if(TetraType::HasTetraColor()){
|
||||
{
|
||||
(*fi).C()[0] = (unsigned char)((fa.colors[0*3+0]*255+fa.colors[1*3+0]*255+fa.colors[2*3+0]*255)/3.0f);
|
||||
(*fi).C()[1] = (unsigned char)((fa.colors[0*3+1]*255+fa.colors[1*3+1]*255+fa.colors[2*3+1]*255)/3.0f);
|
||||
(*fi).C()[2] = (unsigned char)((fa.colors[0*3+2]*255+fa.colors[1*3+2]*255+fa.colors[2*3+2]*255)/3.0f);
|
||||
}
|
||||
(*ti).C()[0] = fa.r;
|
||||
(*ti).C()[1] = fa.g;
|
||||
(*ti).C()[2] = fa.b;
|
||||
(*ti).C()[3] = fa.a;
|
||||
}
|
||||
++ti;
|
||||
}
|
||||
|
||||
for(k=0;k<pi.fdn;k++)
|
||||
memcpy((char *)(&(*fi)) + pi.TetraData[k].offset1,
|
||||
memcpy((char *)(&(*ti)) + pi.TetraData[k].offset1,
|
||||
(char *)(&fa) + FPV[k].offset1,
|
||||
FPV[k].memtypesize());
|
||||
++fi;
|
||||
}
|
||||
// }
|
||||
//else if( !strcmp( pf.ElemName(i),"tristrips") )//////////////////// LETTURA TRISTRIP DI STANFORD
|
||||
// {
|
||||
// int j;
|
||||
// pf.SetCurElement(i);
|
||||
// int numvert_tmp = m.vert.size();
|
||||
// for(j=0;j<n;++j)
|
||||
// {
|
||||
// int k;
|
||||
// if(pi.cb && (j%1000)==0) pi.cb(50+j*50/n,"Tristrip Face Loading");
|
||||
// if( pf.Read(&tsa)==-1 )
|
||||
// {
|
||||
// pi.status = PlyInfo::E_SHORTFILE;
|
||||
// return -1;
|
||||
// }
|
||||
// int remainder=0;
|
||||
// //int startface=m.face.size();
|
||||
// for(k=0;k<tsa.size-2;++k)
|
||||
// {
|
||||
// if(pi.cb && (k%1000)==0) pi.cb(50+k*50/tsa.size,"Tristrip Face Loading");
|
||||
// if(tsa.v[k]<0 || tsa.v[k]>=numvert_tmp ) {
|
||||
// pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
||||
// return -1;
|
||||
// }
|
||||
// if(tsa.v[k+2]==-1)
|
||||
// {
|
||||
// k+=2;
|
||||
// if(k%2) remainder=0;
|
||||
// else remainder=1;
|
||||
// continue;
|
||||
// }
|
||||
// tf.V(0) = index[ tsa.v[k+0] ];
|
||||
// tf.V(1) = index[ tsa.v[k+1] ];
|
||||
// tf.V(2) = index[ tsa.v[k+2] ];
|
||||
// if((k+remainder)%2) swap (tf.V(0), tf.V(1) );
|
||||
// m.face.push_back( tf );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
else
|
||||
{
|
||||
// Skippaggio elementi non gestiti
|
||||
|
@ -635,79 +484,79 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi )
|
|||
}
|
||||
|
||||
|
||||
// Caricamento camera da un ply
|
||||
int LoadCamera(const char * filename)
|
||||
{
|
||||
vcg::ply::PlyFile pf;
|
||||
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
||||
{
|
||||
pi.status = pf.GetError();
|
||||
return -1;
|
||||
}
|
||||
// // Caricamento camera da un ply
|
||||
// int LoadCamera(const char * filename)
|
||||
// {
|
||||
// vcg::ply::PlyFile pf;
|
||||
// if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
||||
// {
|
||||
// pi.status = pf.GetError();
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
|
||||
bool found = true;
|
||||
int i;
|
||||
for(i=0;i<23;++i)
|
||||
{
|
||||
if( pf.AddToRead(CameraDesc(i))==-1 )
|
||||
{
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// bool found = true;
|
||||
// int i;
|
||||
// for(i=0;i<23;++i)
|
||||
// {
|
||||
// if( pf.AddToRead(CameraDesc(i))==-1 )
|
||||
// {
|
||||
// found = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
if(!found)
|
||||
return -1;
|
||||
// if(!found)
|
||||
// return -1;
|
||||
|
||||
for(i=0;i<int(pf.elements.size());i++)
|
||||
{
|
||||
int n = pf.ElemNumber(i);
|
||||
// for(i=0;i<int(pf.elements.size());i++)
|
||||
// {
|
||||
// int n = pf.ElemNumber(i);
|
||||
|
||||
if( !strcmp( pf.ElemName(i),"camera" ) )
|
||||
{
|
||||
pf.SetCurElement(i);
|
||||
// if( !strcmp( pf.ElemName(i),"camera" ) )
|
||||
// {
|
||||
// pf.SetCurElement(i);
|
||||
|
||||
//LoadPly_Camera ca;
|
||||
// //LoadPly_Camera ca;
|
||||
|
||||
for(int j=0;j<n;++j)
|
||||
{
|
||||
if( pf.Read( (void *)&(ca) )==-1 )
|
||||
{
|
||||
pi.status = PlyInfo::E_SHORTFILE;
|
||||
return -1;
|
||||
}
|
||||
camera.valid = true;
|
||||
camera.view_p[0] = ca.view_px;
|
||||
camera.view_p[1] = ca.view_py;
|
||||
camera.view_p[2] = ca.view_pz;
|
||||
camera.x_axis[0] = ca.x_axisx;
|
||||
camera.x_axis[1] = ca.x_axisy;
|
||||
camera.x_axis[2] = ca.x_axisz;
|
||||
camera.y_axis[0] = ca.y_axisx;
|
||||
camera.y_axis[1] = ca.y_axisy;
|
||||
camera.y_axis[2] = ca.y_axisz;
|
||||
camera.z_axis[0] = ca.z_axisx;
|
||||
camera.z_axis[1] = ca.z_axisy;
|
||||
camera.z_axis[2] = ca.z_axisz;
|
||||
camera.f = ca.focal;
|
||||
camera.s[0] = ca.scalex;
|
||||
camera.s[1] = ca.scaley;
|
||||
camera.c[0] = ca.centerx;
|
||||
camera.c[1] = ca.centery;
|
||||
camera.viewport[0] = ca.viewportx;
|
||||
camera.viewport[1] = ca.viewporty;
|
||||
camera.k[0] = ca.k1;
|
||||
camera.k[1] = ca.k2;
|
||||
camera.k[2] = ca.k3;
|
||||
camera.k[3] = ca.k4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// for(int j=0;j<n;++j)
|
||||
// {
|
||||
// if( pf.Read( (void *)&(ca) )==-1 )
|
||||
// {
|
||||
// pi.status = PlyInfo::E_SHORTFILE;
|
||||
// return -1;
|
||||
// }
|
||||
// camera.valid = true;
|
||||
// camera.view_p[0] = ca.view_px;
|
||||
// camera.view_p[1] = ca.view_py;
|
||||
// camera.view_p[2] = ca.view_pz;
|
||||
// camera.x_axis[0] = ca.x_axisx;
|
||||
// camera.x_axis[1] = ca.x_axisy;
|
||||
// camera.x_axis[2] = ca.x_axisz;
|
||||
// camera.y_axis[0] = ca.y_axisx;
|
||||
// camera.y_axis[1] = ca.y_axisy;
|
||||
// camera.y_axis[2] = ca.y_axisz;
|
||||
// camera.z_axis[0] = ca.z_axisx;
|
||||
// camera.z_axis[1] = ca.z_axisy;
|
||||
// camera.z_axis[2] = ca.z_axisz;
|
||||
// camera.f = ca.focal;
|
||||
// camera.s[0] = ca.scalex;
|
||||
// camera.s[1] = ca.scaley;
|
||||
// camera.c[0] = ca.centerx;
|
||||
// camera.c[1] = ca.centery;
|
||||
// camera.viewport[0] = ca.viewportx;
|
||||
// camera.viewport[1] = ca.viewporty;
|
||||
// camera.k[0] = ca.k1;
|
||||
// camera.k[1] = ca.k2;
|
||||
// camera.k[2] = ca.k3;
|
||||
// camera.k[3] = ca.k4;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
|
||||
bool LoadMask(const char * filename, int &mask)
|
||||
|
@ -722,25 +571,23 @@ bool LoadMask(const char * filename, int &mask)
|
|||
|
||||
if( pf.AddToRead(VertDesc(0))!=-1 &&
|
||||
pf.AddToRead(VertDesc(1))!=-1 &&
|
||||
pf.AddToRead(VertDesc(2))!=-1 ) mask |= ply::PLYMask::PM_VERTCOORD;
|
||||
pf.AddToRead(VertDesc(2))!=-1 ) mask |= vcg::tetra::io::Mask::IOM_VERTCOORD;
|
||||
|
||||
if( pf.AddToRead(VertDesc(3))!=-1 ) mask |= ply::PLYMask::PM_VERTFLAGS;
|
||||
if( pf.AddToRead(VertDesc(4))!=-1 ) mask |= ply::PLYMask::PM_VERTQUALITY;
|
||||
if( pf.AddToRead(VertDesc(8))!=-1 ) mask |= ply::PLYMask::PM_VERTQUALITY;
|
||||
if( pf.AddToRead(VertDesc(3))!=-1 ) mask |= vcg::tetra::io::Mask::IOM_VERTFLAGS;
|
||||
if( pf.AddToRead(VertDesc(4))!=-1 ) mask |= vcg::tetra::io::Mask::IOM_VERTQUALITY;
|
||||
if( ( pf.AddToRead(VertDesc(5))!=-1 ) &&
|
||||
( pf.AddToRead(VertDesc(6))!=-1 ) &&
|
||||
( pf.AddToRead(VertDesc(7))!=-1 ) ) mask |= ply::PLYMask::PM_VERTCOLOR;
|
||||
( pf.AddToRead(VertDesc(7))!=-1 ) &&
|
||||
( pf.AddToRead(VertDesc(8))!=-1 ) ) mask |= vcg::tetra::io::Mask::IOM_VERTCOLOR;
|
||||
|
||||
if( pf.AddToRead(TetraDesc(0))!=-1 ) mask |= ply::PLYMask::PM_TETRAINDEX;
|
||||
if( pf.AddToRead(TetraDesc(1))!=-1 ) mask |= ply::PLYMask::PM_TETRAFLAGS;
|
||||
if( pf.AddToRead(TetraDesc(0))!=-1 ) mask |= vcg::tetra::io::Mask::IOM_TETRAINDEX;
|
||||
if( pf.AddToRead(TetraDesc(1))!=-1 ) mask |= vcg::tetra::io::Mask::IOM_TETRAFLAGS;
|
||||
|
||||
if( pf.AddToRead(TetraDesc(2))!=-1 ) mask |= ply::PLYMask::PM_TETRAQUALITY;
|
||||
//if( pf.AddToRead(TetraDesc(3))!=-1 ) mask |= ply::PLYMask::PM_WEDGTEXCOORD;
|
||||
//if( pf.AddToRead(TetraDesc(5))!=-1 ) mask |= ply::PLYMask::PM_WEDGTEXMULTI;
|
||||
if( pf.AddToRead(TetraDesc(4))!=-1 ) mask |= ply::PLYMask::PM_WEDGCOLOR;
|
||||
if( pf.AddToRead(TetraDesc(2))!=-1 ) mask |= vcg::tetra::io::Mask::IOM_TETRAQUALITY;
|
||||
if( ( pf.AddToRead(TetraDesc(6))!=-1 ) &&
|
||||
( pf.AddToRead(TetraDesc(7))!=-1 ) &&
|
||||
( pf.AddToRead(TetraDesc(8))!=-1 ) ) mask |= ply::PLYMask::PM_TETRACOLOR;
|
||||
( pf.AddToRead(TetraDesc(8))!=-1 ) &&
|
||||
( pf.AddToRead(TetraDesc(9))!=-1 ) ) mask |= vcg::tetra::io::Mask::IOM_TETRACOLOR;
|
||||
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue