First working version (tetrahedron!)

This commit is contained in:
Paolo Cignoni 2004-03-03 16:11:46 +00:00
parent 71749144a2
commit f657ab9c6c
1 changed files with 512 additions and 518 deletions

View File

@ -1,68 +1,60 @@
/*#***************************************************************************
* VertexBase.h o o *
* o o *
* Visual Computing Group _ O _ *
* IEI Institute, CNUCE Institute, CNR Pisa \/)\/ *
* /\/| *
* Copyright(C) 1999 by Paolo Cignoni, Claudio Rocchini | *
* All rights reserved. \ *
* *
* Permission to use, copy, modify, distribute and sell this software and *
* its documentation for any purpose is hereby granted without fee, provided *
* that the above copyright notice appear in all copies and that both that *
* copyright notice and this permission notice appear in supporting *
* documentation. the author makes no representations about the suitability *
* of this software for any purpose. It is provided "as is" without express *
* or implied warranty. *
* *
*****************************************************************************/
/****************************************************************************
* 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
2000 Jul 23 First Working release (only the tetrahedron)
30 Added Octahedron
Aug 4 Added Icosahedron
Nov 22 Added Hexahedron (cube)
2001 Apr 19 Added HalfOctahedron
20 Added Square
May 16 Added Sphere Function (CR) (PC)
" Cone " " "
" Box (CR)
Jul 09 Aggiunta Build (CR)
****************************************************************************/
$Log: not supported by cvs2svn $
****************************************************************************/
#ifndef __VCGLIB_PLATONIC
#define __VCGLIB_PLATONIC
#include <vcg/Mesh/Refine.h>
//#include <vcg/Mesh/Refine.h>
#include<vcg/complex/trimesh/allocate.h>
namespace vcg {
namespace tri {
template <class MESH_TYPE>
void Tetrahedron(MESH_TYPE &in)
{
in.vn=4;
in.fn=4;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
in.Clear();
Allocator<MESH_TYPE>::AddVertices(in,4);
Allocator<MESH_TYPE>::AddFaces(in,4);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
MESH_TYPE::VertexPointer ivp[4];
MESH_TYPE::face_type f;f.Supervisor_Flags()=0;
MESH_TYPE::VertexIterator vi=in.vert.begin();
ivp[0]=&*vi;(*vi).P()=MESH_TYPE::CoordType ( 1, 1, 1); ++vi;
ivp[1]=&*vi;(*vi).P()=MESH_TYPE::CoordType (-1, 1,-1); ++vi;
ivp[2]=&*vi;(*vi).P()=MESH_TYPE::CoordType (-1,-1, 1); ++vi;
ivp[3]=&*vi;(*vi).P()=MESH_TYPE::CoordType ( 1,-1,-1);
MESH_TYPE::vertex_iterator vi;
int j;
for(j=0,vi=in.vert.begin();j<in.vn;++j,++vi) index[j] = &*vi;
f.V(0)=index[0]; f.V(1)=index[1];f.V(2)=index[2]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[2];f.V(2)=index[3]; in.face.push_back(f);
f.V(0)=index[0]; f.V(1)=index[3];f.V(2)=index[1]; in.face.push_back(f);
f.V(0)=index[3]; f.V(1)=index[2];f.V(2)=index[1]; in.face.push_back(f);
MESH_TYPE::FaceIterator fi=in.face.begin();
(*fi).V(0)=ivp[0]; (*fi).V(1)=ivp[1]; (*fi).V(2)=ivp[2]; ++fi;
(*fi).V(0)=ivp[0]; (*fi).V(1)=ivp[2]; (*fi).V(2)=ivp[3]; ++fi;
(*fi).V(0)=ivp[0]; (*fi).V(1)=ivp[3]; (*fi).V(2)=ivp[1]; ++fi;
(*fi).V(0)=ivp[3]; (*fi).V(1)=ivp[2]; (*fi).V(2)=ivp[1];
}
template <class MESH_TYPE>
@ -72,14 +64,14 @@ void Octahedron(MESH_TYPE &in)
in.fn=8;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 0, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 0,-1); tv.P()=tp; in.vert.push_back(tv);
MESH_TYPE::VertexType tv;tv.Supervisor_Flags()=0;
MESH_TYPE::CoordType tp;
tp=MESH_TYPE::CoordType ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0, 0, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0, 0,-1); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
@ -102,22 +94,22 @@ void Octahedron(MESH_TYPE &in)
template <class MESH_TYPE>
void Icosahedron(MESH_TYPE &in)
{
MESH_TYPE::scalar_type L=(Sqrt(5.0)+1.0)/2.0;
MESH_TYPE::vectorial_type vv[12]={
MESH_TYPE::vectorial_type ( 0, L, 1),
MESH_TYPE::vectorial_type ( 0, L,-1),
MESH_TYPE::vectorial_type ( 0,-L, 1),
MESH_TYPE::vectorial_type ( 0,-L,-1),
MESH_TYPE::ScalarType L=(Sqrt(5.0)+1.0)/2.0;
MESH_TYPE::CoordType vv[12]={
MESH_TYPE::CoordType ( 0, L, 1),
MESH_TYPE::CoordType ( 0, L,-1),
MESH_TYPE::CoordType ( 0,-L, 1),
MESH_TYPE::CoordType ( 0,-L,-1),
MESH_TYPE::vectorial_type ( L, 1, 0),
MESH_TYPE::vectorial_type ( L,-1, 0),
MESH_TYPE::vectorial_type (-L, 1, 0),
MESH_TYPE::vectorial_type (-L,-1, 0),
MESH_TYPE::CoordType ( L, 1, 0),
MESH_TYPE::CoordType ( L,-1, 0),
MESH_TYPE::CoordType (-L, 1, 0),
MESH_TYPE::CoordType (-L,-1, 0),
MESH_TYPE::vectorial_type ( 1, 0, L),
MESH_TYPE::vectorial_type (-1, 0, L),
MESH_TYPE::vectorial_type ( 1, 0,-L),
MESH_TYPE::vectorial_type (-1, 0,-L)
MESH_TYPE::CoordType ( 1, 0, L),
MESH_TYPE::CoordType (-1, 0, L),
MESH_TYPE::CoordType ( 1, 0,-L),
MESH_TYPE::CoordType (-1, 0,-L)
};
int ff[20][3]={
@ -132,8 +124,8 @@ void Icosahedron(MESH_TYPE &in)
in.fn=20;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
MESH_TYPE::VertexType tv;tv.Supervisor_Flags()=0;
MESH_TYPE::CoordType tp;
for(int i=0;i<in.vn;i++)
{
tv.P()=vv[i];
@ -163,16 +155,16 @@ void Hexahedron(MESH_TYPE &in)
in.fn=12;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type (-1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
MESH_TYPE::VertexType tv;tv.Supervisor_Flags()=0;
MESH_TYPE::CoordType tp;
tp=MESH_TYPE::CoordType (-1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 1,-1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (-1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 1, 1,-1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (-1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 1,-1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (-1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 1, 1, 1); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
@ -207,13 +199,13 @@ void HalfOctahedron(MESH_TYPE &in)
in.fn=4;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 0, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
MESH_TYPE::VertexType tv;tv.Supervisor_Flags()=0;
MESH_TYPE::CoordType tp;
tp=MESH_TYPE::CoordType ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0, 0, 1); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
@ -240,12 +232,12 @@ void Square(MESH_TYPE &in)
in.fn=2;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
MESH_TYPE::VertexType tv;tv.Supervisor_Flags()=0;
MESH_TYPE::CoordType tp;
tp=MESH_TYPE::CoordType ( 1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0, 1, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (-1, 0, 0); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType ( 0,-1, 0); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
@ -281,9 +273,9 @@ void Sphere(MESH_TYPE &in, const int subdiv = 3 )
/// r1 = raggio 1, r2 = raggio2, h = altezza (asse y)
template <class MESH_TYPE>
void Cone( MESH_TYPE & in,
const MESH_TYPE::scalar_type r1,
const MESH_TYPE::scalar_type r2,
const MESH_TYPE::scalar_type h )
const typename MESH_TYPE::ScalarType r1,
const typename MESH_TYPE::ScalarType r2,
const typename MESH_TYPE::ScalarType h )
{
const int D = 24;
int i,b1,b2;
@ -302,14 +294,14 @@ void Cone( MESH_TYPE & in,
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
MESH_TYPE::VertexType tv;tv.Supervisor_Flags()=0;
MESH_TYPE::CoordType tp;
tp=MESH_TYPE::vectorial_type ( 0,-h/2,0 );
tp=MESH_TYPE::CoordType ( 0,-h/2,0 );
tv.P()=tp;
in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type ( 0, h/2,0 );
tp=MESH_TYPE::CoordType ( 0, h/2,0 );
tv.P()=tp;
in.vert.push_back(tv);
@ -326,7 +318,7 @@ void Cone( MESH_TYPE & in,
x = r1*c;
z = r1*s;
y = -h/2;
tp=MESH_TYPE::vectorial_type ( x,y,z );
tp=MESH_TYPE::CoordType ( x,y,z );
tv.P()=tp;
in.vert.push_back(tv);
}
@ -344,7 +336,7 @@ void Cone( MESH_TYPE & in,
x = r2*c;
z = r2*s;
y = h/2;
tp=MESH_TYPE::vectorial_type ( x,y,z );
tp=MESH_TYPE::CoordType ( x,y,z );
tv.P()=tp;
in.vert.push_back(tv);
}
@ -419,22 +411,22 @@ void Cone( MESH_TYPE & in,
template <class MESH_TYPE>
void Box(MESH_TYPE &in, const MESH_TYPE::BOX_TYPE & bb )
void Box(MESH_TYPE &in, const typename MESH_TYPE::BoxType & bb )
{
in.vn=8;
in.fn=12;
in.vert.clear();
in.face.clear();
MESH_TYPE::vertex_type tv;tv.Supervisor_Flags()=0;
MESH_TYPE::vectorial_type tp;
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.min[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.min[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.max[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.max[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.min[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.min[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.min[0],bb.max[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::vectorial_type (bb.max[0],bb.max[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
MESH_TYPE::VertexType tv;tv.Supervisor_Flags()=0;
MESH_TYPE::CoordType tp;
tp=MESH_TYPE::CoordType (bb.min[0],bb.min[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (bb.max[0],bb.min[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (bb.min[0],bb.max[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (bb.max[0],bb.max[1],bb.min[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (bb.min[0],bb.min[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (bb.max[0],bb.min[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (bb.min[0],bb.max[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
tp=MESH_TYPE::CoordType (bb.max[0],bb.max[1],bb.max[2]); tv.P()=tp; in.vert.push_back(tv);
vector<MESH_TYPE::vertex_pointer> index(in.vn);
@ -476,15 +468,15 @@ void Build( M & in, const V & v, const F & f)
V::const_iterator vi;
M::vertex_type tv;
M::VertexType tv;
tv.Supervisor_Flags()=0;
for(vi=v.begin();vi!=v.end();++vi)
{
tv.P() = M::vectorial_type(
(M::scalar_type)(*vi).Ext(0),
(M::scalar_type)(*vi).Ext(1),
(M::scalar_type)(*vi).Ext(2)
tv.P() = M::CoordType(
(M::ScalarType)(*vi).Ext(0),
(M::ScalarType)(*vi).Ext(1),
(M::ScalarType)(*vi).Ext(2)
);
in.vert.push_back(tv);
}
@ -515,4 +507,6 @@ void Build( M & in, const V & v, const F & f)
}
}
} // End Namespace TriMesh
} // End Namespace vcg
#endif