51static void compute_dimensions(
82 Resolution = resolution;
86 XDim = resolution + 1;
87 YDim = resolution + 1;
88 ZDim = resolution + 1;
98 VisData =
new uint8[XDim * YDim * ZDim];
99 if (VisData ==
NULL) {
103 memset(VisData,0,XDim*YDim*ZDim);
112 compute_dimensions(meshlist,ParentTM,CurTime,&
min,&
max);
127 Scale.x = Resolution / Size.x;
128 Scale.y = Resolution / Size.y;
129 Scale.z = Resolution / Size.z;
135 BlockXDim = Size.x / Resolution;
136 BlockYDim = Size.y / Resolution;
137 BlockZDim = Size.z / Resolution;
166 if (VisData !=
NULL)
delete[] VisData;
183void VoxelClass::Quantize_Meshes
194 slabmeter.Finish_In_Steps(ZDim);
199 float min_z = Offset.z;
200 float max_z = Offset.z + Size.z;
201 float sliceh = Size.z / (float)ZDim;
203 for (
int slicecount = 0; slicecount < ZDim; slicecount++ )
205 float slicez = min_z + (max_z - min_z) * ((
float)slicecount/(
float)(ZDim-1));
220 Set_Layer(*vlayer,slicecount);
222 slabmeter.Add_Increment();
223 if (slabmeter.Cancelled())
throw ErrorClass(
"Export Cancelled");
231 Progress_Meter_Class vismeter(meter,meter.
Increment);
232 Compute_Visiblity(vismeter);
237 Compute_Bounding_Box(Size,Offset);
254void VoxelClass::Set_Layer
261 if (vlayer.
Get_Width() != (
unsigned)XDim)
return;
262 if (vlayer.
Get_Height() != (
unsigned)YDim)
return;
266 for (
unsigned j=0; j<vlayer.
Get_Height(); j++) {
267 for (
unsigned i=0; i<vlayer.
Get_Width(); i++) {
293void VoxelClass::Compute_Bounding_Box
306 BoxCorner[0].x = offset.x + size.x;
307 BoxCorner[0].y = offset.y + size.y;
308 BoxCorner[0].z = offset.z;
311 BoxCorner[1].x = offset.x + size.x;
312 BoxCorner[1].y = offset.y;
313 BoxCorner[1].z = offset.z;
316 BoxCorner[2].x = offset.x;
317 BoxCorner[2].y = offset.y;
318 BoxCorner[2].z = offset.z;
321 BoxCorner[3].x = offset.x;
322 BoxCorner[3].y = offset.y + size.y;
323 BoxCorner[3].z = offset.z;
326 BoxCorner[4].x = offset.x + size.x;
327 BoxCorner[4].y = offset.y + size.y;
328 BoxCorner[4].z = offset.z + size.z;
331 BoxCorner[5].x = offset.x + size.x;
332 BoxCorner[5].y = offset.y;
333 BoxCorner[5].z = offset.z + size.z;
336 BoxCorner[6].x = offset.x;
337 BoxCorner[6].y = offset.y;
338 BoxCorner[6].z = offset.z + size.z;
341 BoxCorner[7].x = offset.x;
342 BoxCorner[7].y = offset.y + size.y;
343 BoxCorner[7].z = offset.z + size.z;
346 for (i=0; i<8; i++) {
347 BoxCorner[i].x *= Scale.x;
348 BoxCorner[i].y *= Scale.y;
349 BoxCorner[i].z *= Scale.z;
372void VoxelClass::Compute_Visiblity
387 for (z = 0; z < (int)ZDim; z++) {
390 for (y = 0; y < (int)YDim; y++) {
392 for (x = 0; x < (int)XDim; x++) {
393 if (raw_read_vis(x,y,z) ==
VIS_SOLID)
break;
397 for (x = (
int)XDim-1; x >= 0; x--) {
398 if (raw_read_vis(x,y,z) ==
VIS_SOLID)
break;
404 for (x = 0; x < (int)XDim; x++) {
406 for (y = 0; y < (int)YDim; y++) {
407 if (raw_read_vis(x,y,z) ==
VIS_SOLID)
break;
411 for (y = (
int)YDim-1; y >= 0; y--) {
412 if (raw_read_vis(x,y,z) ==
VIS_SOLID)
break;
418 if (meter.
Cancelled())
throw ErrorClass(
"Export Cancelled");
428 for (x = 0; x < (int)XDim; x++) {
431 for (y = 0; y < (int)YDim; y++) {
433 for (z = 0; z < (int)ZDim; z++) {
434 if (raw_read_vis(x,y,z) ==
VIS_SOLID)
break;
438 for (z = (
int)ZDim-1; z >= 0; z--) {
439 if (raw_read_vis(x,y,z) ==
VIS_SOLID)
break;
445 if (meter.
Cancelled())
throw ErrorClass(
"Export Cancelled");
453 for (z = 0; z < (int)ZDim; z++) {
454 for (y = 0; y < (int)YDim; y++) {
455 for (x = 0; x < (int)XDim; x++) {
457 int vis = raw_read_vis(x,y,z);
465 if (meter.
Cancelled())
throw ErrorClass(
"Export Cancelled");
482uint8 VoxelClass::raw_read_vis
492 if (i>=(
int)XDim)
return 0;
493 if (j>=(
int)YDim)
return 0;
494 if (k>=(
int)ZDim)
return 0;
496 return VisData[i + j*XDim + k*XDim*YDim];
512void VoxelClass::raw_set_vis(
522 if (i>=(
int)XDim)
return;
523 if (j>=(
int)YDim)
return;
524 if (k>=(
int)ZDim)
return;
526 VisData[i + j*XDim + k*XDim*YDim] = val;
531void compute_dimensions
544 float surface_area = 0.0;
548 for (
unsigned i = 0; i < meshlist.
Num_Nodes() ; ++ i )
552 INode * n = meshlist[i];
553 Object * obj = n->EvalWorldState(curtime).obj;
554 TriObject * tri = (TriObject *)obj->ConvertToType(curtime, triObjectClassID);
555 Mesh * mesh = &(tri->mesh);
556 Matrix3 tm = n->GetObjTMAfterWSM(curtime);
563 unsigned verts = mesh->getNumVerts();
564 unsigned faces = mesh->getNumFaces();
566 for (
unsigned vert_index = 0; vert_index < verts; ++ vert_index )
568 Point3 p = delta * mesh->verts [vert_index];
577 if ( p.x <
min.x )
min.x = p.x;
578 if ( p.y <
min.y )
min.y = p.y;
579 if ( p.z <
min.z )
min.z = p.z;
581 if ( p.x >
max.x )
max.x = p.x;
582 if ( p.y >
max.y )
max.y = p.y;
583 if ( p.z >
max.z )
max.z = p.z;
587 for (
unsigned face_index = 0; face_index < faces; ++ face_index )
589 Face face = mesh->faces [ face_index ];
591 Point3 a = mesh->verts [ face.v[0] ];
592 Point3 b = mesh->verts [ face.v[1] ];
593 Point3 c = mesh->verts [ face.v[2] ];
595 double area = 0.5 * Length ( CrossProd ( b - a, c - a ) );
597 surface_area += (float) area;
604 min =
max = Point3 (0,0,0);
613 return (raw_read_vis(i,j,k) ==
VIS_SOLID);
621 double bvol = BlockXDim * BlockYDim * BlockZDim;
625 Point3 cm(0.0,0.0,0.0);
631 for (k=0; k < ZDim; k++) {
632 for (j=0; j < YDim; j++) {
633 for (i=0; i < XDim; i++) {
640 cm += Voxel_Position(i,j,k);
647 cm.x = cm.x / (double)numblocks;
648 cm.y = cm.y / (double)numblocks;
649 cm.z = cm.z / (double)numblocks;
674 for (i=0; i < 9; i++) {
678 for (k=0; k < ZDim; k++) {
679 for (j=0; j < YDim; j++) {
680 for (i=0; i < XDim; i++) {
684 Point3 pos = Voxel_Position(i,j,k) - cm;
687 double y2z2 = pos.y * pos.y + pos.z * pos.z;
688 double x2z2 = pos.x * pos.x + pos.z * pos.z;
689 double x2y2 = pos.x * pos.x + pos.y * pos.y;
692 double xy = pos.x * pos.y;
693 double xz = pos.x * pos.z;
694 double yz = pos.y * pos.z;
714Point3 VoxelClass::Voxel_Position(
int i,
int j,
int k)
718 Offset.x + i * BlockXDim + BlockXDim / 2.0,
719 Offset.y + j * BlockYDim + BlockYDim / 2.0,
720 Offset.z + k * BlockZDim + BlockZDim / 2.0
unsigned Num_Nodes(void) const
void Finish_In_Steps(int number_of_steps)
void Compute_Physical_Properties(double Volume[1], double CM[3], double I[9])
uint8 Is_Solid(int i, int j, int k)
VoxelClass(INodeListClass &meshlist, int resolution, Matrix3 parenttm, TimeValue time, Progress_Meter_Class &meter)
BOOL Is_Solid(int x, int y)
unsigned int Get_Height(void)
unsigned int Get_Width(void)
WWINLINE Quaternion Inverse(const Quaternion &a)