5 #ifndef BALL_DATATYPE_CONTOURSURFACE_H
6 #define BALL_DATATYPE_CONTOURSURFACE_H
12 #ifndef BALL_DATATYPE_REGULARDATA3D_H
16 #ifndef BALL_MATHS_SURFACE_H
20 #ifndef BALL_DATATYPE_HASHMAP_H
27 #ifdef BALL_HAS_HASH_MAP
28 namespace BALL_MAP_NAMESPACE
31 struct hash<std::pair<BALL::Position, BALL::Position> >
33 size_t operator () (
const std::pair<BALL::Position, BALL::Position>& p)
const
34 {
return (
size_t)(p.first + p.second);}
68 typedef std::pair<Position, Position>
KeyType;
78 typedef std::vector<std::pair<PointType, std::pair<Position, Position> > >
VectorType;
112 virtual void clear();
212 static const Position topology_modifier[8] = {1, 2, 4, 8, 16, 32, 64, 128};
220 topology |= ((
values[i] > threshold) ? topology_modifier[i] : 0);
265 template <
typename T>
271 template <
typename T>
273 : threshold_(threshold)
277 template <
typename T>
279 : threshold_(threshold)
284 template <
typename T>
289 template <
typename T>
291 : threshold_(from.threshold_)
295 template <
typename T>
299 cut_hash_map_.clear();
302 template <
typename T>
314 template <
typename T>
318 && Surface::operator == (data.data_));
321 template <
typename T>
343 for (
Position curr_cell_z = 0; curr_cell_z < (number_of_cells_z - 1); curr_cell_z++)
346 current_index = curr_cell_z * number_of_cells_y * number_of_cells_x;
349 for (
Position curr_cell_y = 0; curr_cell_y < (number_of_cells_y - 1); curr_cell_y++)
353 cube.
setTo(current_index);
356 for (
Position curr_cell_x = 0; (curr_cell_x < (number_of_cells_x - 2)); )
359 addTriangles_(cube, facet_data);
368 addTriangles_(cube, facet_data);
371 current_index += number_of_cells_x;
376 for (
Position i = 0; i < normal.size(); i++)
380 normal[i].normalize();
391 template <
typename T>
399 static std::pair<Position, Position> key;
400 static std::pair<Position, Position> indices;
403 static const Position edge_indices[12][2]
404 = {{1, 0}, {1, 2}, {2, 3}, {0, 3}, {5, 4}, {5, 6},
405 {6, 7}, {4, 7}, {0, 4}, {1, 5}, {2, 6}, {3, 7}
411 = {2, 0, 2, 0, 2, 0, 2, 0, 1, 1, 1, 1};
421 Size vertex_counter = 0;
436 Index facet_index = facet_data[topology][i];
439 if (facet_index != -1)
444 Position edge = edge_axis[facet_index];
446 indices.first = edge_indices[facet_index][0];
447 indices.second = edge_indices[facet_index][1];
448 key.first = cube.
getIndex(indices.first);
449 key.second = cube.
getIndex(indices.second);
452 if (!cut_hash_map_.has(key))
460 const double& d1 = cube.
values[indices.first];
461 const double& d2 = cube.
values[indices.second];
462 pos[edge] += ((
double)threshold_ - d1) / (d2 - d1) * spacing[edge];
465 triangle_vertices[vertex_counter++] = vertex.size();
469 cut_hash_map_.insert(std::pair<std::pair<Position, Position>,
Position>(key, (
Size)vertex.size()));
472 vertex.push_back(pos);
473 static Vector3 null_normal(0.0, 0.0, 0.0);
474 normal.push_back(null_normal);
479 triangle_vertices[vertex_counter++] = cut_hash_map_[key];
483 if (vertex_counter == 3)
486 t.v1 = triangle_vertices.
x;
487 t.v2 = triangle_vertices.
y;
488 t.v3 = triangle_vertices.
z;
489 triangle.push_back(t);
497 Vector3 h1(vertex[t.v1] - vertex[t.v2]);
498 Vector3 h2(vertex[t.v3] - vertex[t.v2]);
500 h1.
z * h2.
x - h2.
z * h1.
x,
501 h1.
x * h2.
y - h1.
y * h2.
x);
502 normal[t.v1] += current_normal;
503 normal[t.v2] += current_normal;
504 normal[t.v3] += current_normal;