2
* Copyright (C) 2001-2005 Terence M. Welsh
4
* This file is part of Implicit.
6
* Implicit is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License version 2.1 as published by the Free Software Foundation.
10
* Implicit is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#ifndef IMPCUBEVOLUME_H
22
#define IMPCUBEVOLUME_H
26
#include <Implicit/impSurface.h>
27
#include <Implicit/impCubeTables.h>
28
#include <Implicit/impCrawlPoint.h>
37
// corner mask which describes how cube is polygonized
39
// position left-lower-far corner (-x, -y, -z)
43
// field value at this corner
45
// edge vertex indices for surfaces
46
unsigned int x_vertex_index;
47
unsigned int y_vertex_index;
48
unsigned int z_vertex_index;
55
// For making a list of cubes to be polygonized.
56
// The list can be sorted by depth before polygonization in
57
// the case of transparent surfaces.
60
unsigned int index; // index of cube in volume
61
float depth; // distance squared from eyepoint
64
sortableCube(unsigned int ind){index = ind;}
67
friend bool operator < (const sortableCube& a, const sortableCube& b){return((a.depth)<(b.depth));}
68
friend bool operator > (const sortableCube& a, const sortableCube& b){return((a.depth)>(b.depth));}
69
friend bool operator == (const sortableCube& a, const sortableCube& b){return((a.depth)==(b.depth));}
70
friend bool operator != (const sortableCube& a, const sortableCube& b){return((a.depth)!=(b.depth));}
76
float (*function)(float* position);
78
float lbf[3]; // left-bottom-far corner of volume
80
unsigned int w, h, l, w_1, h_1, l_1;
81
unsigned int triStripPatterns[256][17];
82
bool crawlDirections[256][6];
83
unsigned int currentVertexIndex;
84
std::vector<cubedata> cubes;
85
std::vector<unsigned int> cubeIndices;
86
std::list<sortableCube> sortableCubes;
87
unsigned int currentCubeIndex;
89
float surfacevalue; // surface's position on gradient
95
// pass dimensions of volume in cubes plus "cubewidth"
96
void init(unsigned int width, unsigned int height, unsigned int length, float cw);
97
void useFastNormals(bool val){fastnormals = val;}
98
void setSurfaceValue(float sv){surfacevalue = sv;}
99
float getSurfaceValue(){return surfacevalue;}
100
void setSurface(impSurface* s){surface = s;}
101
impSurface* getSurface(){return surface;}
102
// These routines compute geometry and store it in "surface"
103
// Providing an eyepoint indicates that you want to sort the surface
104
// so that transparent surfaces will be drawn back-to-front.
105
// Providing a list of crawlpoints indicates that you want to use a
106
// surface crawling algorithm.
107
// If no crawlpoint list is provided, then every cube is checked, which
108
// is slow but thorough (there's no chance of missing a piece of the
111
void makeSurface(float eyex, float eyey, float eyez);
112
void makeSurface(impCrawlPointVector &cpv);
113
void makeSurface(float eyex, float eyey, float eyez, impCrawlPointVector &cpv);
116
// x, y, and z define position of cube in this volume
117
inline unsigned int calculateCornerMask(unsigned int x, unsigned int y, unsigned int z);
118
inline void crawl_nosort(unsigned int x, unsigned int y, unsigned int z);
119
inline void crawl_sort(unsigned int x, unsigned int y, unsigned int z);
120
inline void uncrawl(unsigned int x, unsigned int y, unsigned int z);
121
inline void polygonize(unsigned int index);
122
inline void findcornervalues(unsigned int x, unsigned int y, unsigned int z);
123
inline void addVertexToSurface(unsigned int axis, unsigned int index);
124
inline unsigned int cubeindex(unsigned int i, unsigned int j, unsigned int k)
125
{ return (((k * h_1) + j) * w_1) + i; }