2 This file is part of the 3dengfx, realtime visualization system.
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
6 3dengfx is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 3dengfx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with 3dengfx; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* Scalar fields and polygonization
23 * Author: Mihalis Georgoulopoulos 2005
27 #include "3dengfx/3denginefx_types.hpp"
28 #include "n3dmath2/n3dmath2.hpp"
29 #include "gfx/3dgeom.hpp"
31 #ifndef _SCALAR_FIELD_HEADER_
32 #define _SCALAR_FIELD_HEADER_
37 scalar_t *values; // array that holds all values of the field
39 unsigned int *edges_x, *edges_y, *edges_z; // x- y- and z-aligned edges.
40 // these arrays hold indices to the
41 // vertex list, associated with the specific edge
43 unsigned int dimensions; // dimensions of the field
44 Vector3 from, to, cell_size; // limits in space of the field
47 std::vector <Vertex> verts;
48 std::vector <Triangle> tris;
51 scalar_t (*evaluate)(const Vector3 &vec, scalar_t t);
52 Vector3 (*get_normal)(const Vector3 &vec, scalar_t t);
55 unsigned int add_vertex(const Vertex &vert); // adds a vertex and returns its index
56 void clear(); // clears the std::vectors that hold mesh data
57 void evaluate_all(scalar_t t);
58 void process_cell(int x, int y, int z, scalar_t isolevel);
60 unsigned int get_value_index(int x, int y, int z);
61 Vector3 def_eval_normals(const Vector3 &vec, scalar_t t);
67 ScalarField(unsigned int dimensions, const Vector3 &from, const Vector3 &to);
70 void set_dimensions(unsigned int dimensions);
73 // if full, draws everything. If not, draws the bounding volume
74 void draw_field(bool full);
77 void set_value(int x, int y, int z, scalar_t value);
78 scalar_t get_value(int x, int y, int z);
80 // get / set relative to cell
81 void set_value(int cx, int cy, int cz, int vert_index, scalar_t value);
82 scalar_t get_value(int cx, int cy, int cz, int vert_index);
84 // edges are only addressed relative to a cell
85 void set_edge(int cx, int cy, int cz, int edge, unsigned int index);
86 unsigned int get_edge(int cx, int cy, int cz, int edge);
89 Vector3 get_position(int x, int y, int z);
90 Vector3 get_position(int cx, int cy, int cz, int vert_index);
91 void set_from_to(const Vector3 &from, const Vector3 &to);
96 void set_evaluator(scalar_t (*evaluate)(const Vector3 &vec, scalar_t t));
97 void set_normal_evaluator(Vector3 (*get_normal)(const Vector3 &vec, scalar_t t));
100 void triangulate(TriMesh *mesh, scalar_t isolevel, scalar_t t, bool calc_normals);
103 #endif // ndef _SCALAR_FIELD_HEADER_