From 66b962e1428894b14ce77743d54d65407587e112 Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 18 May 2009 14:13:46 +0000 Subject: [PATCH] Moved simple_volume into the trivial_walker.h file. --- .../trimesh_isosurface/trimesh_isosurface.cpp | 1 - .../trimesh_isosurface/trivial_walker.h | 125 +++++++++++++++++- 2 files changed, 122 insertions(+), 4 deletions(-) diff --git a/apps/sample/trimesh_isosurface/trimesh_isosurface.cpp b/apps/sample/trimesh_isosurface/trimesh_isosurface.cpp index 0ae95efa..6fbffe31 100644 --- a/apps/sample/trimesh_isosurface/trimesh_isosurface.cpp +++ b/apps/sample/trimesh_isosurface/trimesh_isosurface.cpp @@ -11,7 +11,6 @@ #include -#include "simple_volume.h" #include "trivial_walker.h" using namespace std; diff --git a/apps/sample/trimesh_isosurface/trivial_walker.h b/apps/sample/trimesh_isosurface/trivial_walker.h index 087ffd78..f1657605 100644 --- a/apps/sample/trimesh_isosurface/trivial_walker.h +++ b/apps/sample/trimesh_isosurface/trivial_walker.h @@ -1,16 +1,135 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2009 \/)\/ * +* 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. * +* * +****************************************************************************/ #ifndef __VCG_TRIVIAL_WALKER #define __VCG_TRIVIAL_WALKER namespace vcg { - namespace tri { + +// Very simple volume class. +// just an example of the interface that the trivial walker expects + +template +class SimpleVolume +{ +public: + typedef VOX_TYPE VoxelType; + std::vector Vol; + + Point3i sz; /// Dimensioni griglia come numero di celle per lato + + const Point3i &ISize() {return sz;}; /// Dimensioni griglia come numero di celle per lato + + void Init(Point3i _sz) + { + sz=_sz; + Vol.resize(sz[0]*sz[1]*sz[2]); + } + + float Val(const int &x,const int &y,const int &z) const { + return cV(x,y,z).V(); + //else return numeric_limits::quiet_NaN( ); + } + + float &Val(const int &x,const int &y,const int &z) { + return V(x,y,z).V(); + //else return numeric_limits::quiet_NaN( ); + } + + VOX_TYPE &V(const int &x,const int &y,const int &z) { + return Vol[x+y*sz[0]+z*sz[0]*sz[1]]; + } + + const VOX_TYPE &cV(const int &x,const int &y,const int &z) const { + return Vol[x+y*sz[0]+z*sz[0]*sz[1]]; + } + + +typedef enum { XAxis=0,YAxis=1,ZAxis=2} VolumeAxis; + +template < class VertexPointerType, VolumeAxis AxisVal > + void GetIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr) +{ + float f1 = Val(p1.X(), p1.Y(), p1.Z())-thr; + float f2 = Val(p2.X(), p2.Y(), p2.Z())-thr; + float u = (float) f1/(f1-f2); + if(AxisVal==XAxis) v->P().X() = (float) p1.X()*(1-u) + u*p2.X(); + else v->P().X() = (float) p1.X(); + if(AxisVal==YAxis) v->P().Y() = (float) p1.Y()*(1-u) + u*p2.Y(); + else v->P().Y() = (float) p1.Y(); + if(AxisVal==ZAxis) v->P().Z() = (float) p1.Z()*(1-u) + u*p2.Z(); + else v->P().Z() = (float) p1.Z(); +} + +template < class VertexPointerType > + void GetXIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr) +{ GetIntercept(p1,p2,v,thr); } + +template < class VertexPointerType > + void GetYIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr) +{ GetIntercept(p1,p2,v,thr); } + +template < class VertexPointerType > + void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr) +{ GetIntercept(p1,p2,v,thr); } +}; +template +class RawVolumeImporter +{ +public: + enum DataType +{ + // Funzioni superiori + UNDEF=0, + BYTE=1, + SHORT=2, + FLOAT=3 +}; + +static bool Open(const char *filename, VolumeType &V, Point3i sz, DataType d) +{ +return true; +} +}; + +class SimpleVoxel +{ +private: + float _v; +public: + float &V() {return _v;}; + float V() const {return _v;}; +}; + + +namespace tri { // La classe Walker implementa la politica di visita del volume; conoscendo l'ordine di visita del volume -// è conveniente che il Walker stesso si faccia carico del caching dei dati utilizzati durante l'esecuzione +// Ë conveniente che il Walker stesso si faccia carico del caching dei dati utilizzati durante l'esecuzione // degli algoritmi MarchingCubes ed ExtendedMarchingCubes, in particolare il calcolo del volume ai vertici // delle celle e delle intersezioni della superficie con le celle. In questo esempio il volume da processare // viene suddiviso in fette; in questo modo se il volume ha dimensione h*l*w (rispettivamente altezza, -// larghezza e profondità), lo spazio richiesto per il caching dei vertici già allocati passa da O(h*l*w) +// larghezza e profondit‡), lo spazio richiesto per il caching dei vertici gi‡ allocati passa da O(h*l*w) // a O(h*l). template