// File: ViewerTest_VoxelCommands.cxx // Created: Wed Sep 17 17:26 2008 // Author: Vlad Romashko // #include #include #include #include #include #include #include #include #include #include #include #include static Standard_Integer VOXELBOOLDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. BoolDS: Voxel_BoolDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds.Set(ix, iy, iz, Standard_False); else ds.Set(ix, iy, iz, Standard_True); } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { Standard_Boolean value = ds.Get(ix, iy, iz) == Standard_True; if (ix & 0x01) { if (value != Standard_False) { di<<"error : voxelboolds"; return 1; // error } } else { if (value != Standard_True) { di<<"error : voxelboolds"; return 1; // error } } } } } return 0; // Sehr gut } static Standard_Integer VOXELCOLORDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. ColorDS: Voxel_ColorDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds.Set(ix, iy, iz, 8); else ds.Set(ix, iy, iz, 7); } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { Standard_Byte value = ds.Get(ix, iy, iz); if (ix & 0x01) { if (value != 8) { di<<"error : voxelcolords"; return 1; } } else { if (value != 7) { di<<"error : voxelcolords"; return 1; } } } } } return 0; } static Standard_Integer VOXELFLOATDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. FloatDS: Voxel_FloatDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds.Set(ix, iy, iz, 8.8f); else ds.Set(ix, iy, iz, 7.7f); } } } /* // Write the voxels Voxel_Writer writer; writer.SetFormat(Voxel_VFF_BINARY); writer.SetVoxels(ds); if (!writer.Write("W:\\OCC621\\samples\\standard\\voxeldemo\\f.vx")) { statusBar()->message( "Storage failed... sorry", 2000 ); return; } // Read the voxels Voxel_Reader reader; if (!reader.Read("W:\\OCC621\\samples\\standard\\voxeldemo\\f.vx")) { statusBar()->message( "Open failed... sorry", 2000 ); return; } */ for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { float value = ds.Get(ix, iy, iz); if (ix & 0x01) { if (value != 8.8f) { di<<"error : voxelfloatds"; return 1; } } else { if (value != 7.7f) { di<<"error : voxelfloatds"; return 1; } } } } } return 0; } static Standard_Integer VOXELOCTBOOLDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 30, nby = 30, nbz = 30; // 1. OctBoolDS: Voxel_OctBoolDS ds(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) { ds.Set(ix, iy, iz, Standard_True); } else { for (Standard_Integer i = 0; i < 8; i++) { if (i & 0x01) ds.Set(ix, iy, iz, i, Standard_True); else ds.Set(ix, iy, iz, i, Standard_False); } } } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) { Standard_Boolean value = ds.Get(ix, iy, iz) == Standard_True; if (value != Standard_True) cout<<"Wrong value!"<OptimizeMemory(); delete ds2; return 0; } static Standard_Integer VOXELFUSEBOOLDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. Set two BoolDS: Voxel_BoolDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz); Voxel_BoolDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds2.Set(ix, iy, iz, Standard_False); else ds2.Set(ix, iy, iz, Standard_True); } } } // 2. Fuse them Voxel_BooleanOperation fuser; if (!fuser.Fuse(ds1, ds2)) { di<<"error : voxelfuseboolds"; return 1; } // 3. Check result for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { Standard_Boolean value = ds1.Get(ix, iy, iz) == Standard_True; if (ix & 0x01) { if (value != Standard_False) { di<<"error : voxelfuseboolds"; return 1; } } else { if (value != Standard_True) { di<<"error : voxelfuseboolds"; return 1; } } } } } return 0; } static Standard_Integer VOXELFUSECOLORDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. Set two ColorDS: Voxel_ColorDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz); Voxel_ColorDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { ds1.Set(ix, iy, iz, 11); } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds2.Set(ix, iy, iz, 3); else ds2.Set(ix, iy, iz, 5); } } } // 2. Fuse them Voxel_BooleanOperation fuser; if (!fuser.Fuse(ds1, ds2)) { di<<"error : voxelfusecolords"; return 1; } // 3. Check result for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { Standard_Byte value = ds1.Get(ix, iy, iz); if (ix & 0x01) { if (value != 14) { di<<"error : voxelfusecolords"; return 1; } } else { if (value != 15) { di<<"error : voxelfusecolords"; return 1; } } } } } return 0; } static Standard_Integer VOXELFUSEFLOATDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. Set two FloatDS: Voxel_FloatDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz); Voxel_FloatDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { ds1.Set(ix, iy, iz, 11.1f); } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds2.Set(ix, iy, iz, 3.3f); else ds2.Set(ix, iy, iz, 5.5f); } } } // 2. Fuse them Voxel_BooleanOperation fuser; if (!fuser.Fuse(ds1, ds2)) { di<<"error : voxelfusefloatds"; return 1; } // 3. Check result for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { float value = ds1.Get(ix, iy, iz); if (ix & 0x01) { if (fabs(value - 14.4f) > 0.001) { di<<"error : voxelfusefloatds"; return 1; } } else { if (fabs(value - 16.6f) > 0.001) { di<<"error : voxelfusefloatds"; return 1; } } } } } return 0; } static Standard_Integer VOXELCUTBOOLDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. Set two BoolDS: Voxel_BoolDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz); Voxel_BoolDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { ds1.Set(ix, iy, iz, Standard_True); } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds2.Set(ix, iy, iz, Standard_False); else ds2.Set(ix, iy, iz, Standard_True); } } } // 2. Cut them Voxel_BooleanOperation cutter; if (!cutter.Cut(ds1, ds2)) { di<<"error : voxelcutboolds"; return 1; } // 3. Check result for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { Standard_Boolean value = ds1.Get(ix, iy, iz) == Standard_True; if (ix & 0x01) { if (value != Standard_True) { di<<"error : voxelcutboolds"; return 1; } } else { if (value != Standard_False) { di<<"error : voxelcutboolds"; return 1; } } } } } return 0; } static Standard_Integer VOXELCUTCOLORDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. Set two ColorDS: Voxel_ColorDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz); Voxel_ColorDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { ds1.Set(ix, iy, iz, 11); } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds2.Set(ix, iy, iz, 3); else ds2.Set(ix, iy, iz, 5); } } } // 2. Cut them Voxel_BooleanOperation cutter; if (!cutter.Cut(ds1, ds2)) { di<<"error : voxelcutcolords"; return 1; } // 3. Check result for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { Standard_Byte value = ds1.Get(ix, iy, iz); if (ix & 0x01) { if (value != 8) { di<<"error : voxelcutcolords"; return 1; } } else { if (value != 6) { di<<"error : voxelcutcolords"; return 1; } } } } } return 0; } static Standard_Integer VOXELCUTFLOATDS(Draw_Interpretor& di, Standard_Integer, const char**) { Standard_Integer ix, iy, iz; Standard_Integer nbx = 100, nby = 100, nbz = 100; // 1. Set two FloatDS: Voxel_FloatDS ds1(0, 0, 0, 1, 1, 1, nbx, nby, nbz); Voxel_FloatDS ds2(0, 0, 0, 1, 1, 1, nbx, nby, nbz); for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { ds1.Set(ix, iy, iz, 11.1f); } } } for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { if (ix & 0x01) ds2.Set(ix, iy, iz, 3.3f); else ds2.Set(ix, iy, iz, 5.5f); } } } // 2. Cut them Voxel_BooleanOperation cutter; if (!cutter.Cut(ds1, ds2)) { di<<"error : voxelcutcolords"; return 1; } // 3. Check result for (ix = 0; ix < nbx; ix++) { for (iy = 0; iy < nby; iy++) { for (iz = 0; iz < nbz; iz++) { float value = ds1.Get(ix, iy, iz); if (ix & 0x01) { if (fabs(value - 7.8f) > 0.001) { di<<"error : voxelcutcolords"; return 1; } } else { if (fabs(value - 5.6f) > 0.001) { di<<"error : voxelcutcolords"; return 1; } } } } } return 0; } void ViewerTest::VoxelCommands(Draw_Interpretor& theCommands) { const char* g = "Viewer Voxel non-regression test-commands"; theCommands.Add("voxelboolds","voxelboolds; returns 0 if success",__FILE__,VOXELBOOLDS,g); theCommands.Add("voxelcolords","voxelcolords; returns 0 if success",__FILE__,VOXELCOLORDS,g); theCommands.Add("voxelfloatds","voxelfloatds; returns 0 if success",__FILE__,VOXELFLOATDS,g); theCommands.Add("voxeloctboolds","voxeloctboolds; returns 0 if success",__FILE__,VOXELOCTBOOLDS,g); theCommands.Add("voxelroctboolds","voxelroctboolds; returns 0 if success",__FILE__,VOXELROCTBOOLDS,g); theCommands.Add("voxelfuseboolds","voxelfuseboolds; returns 0 if success",__FILE__,VOXELFUSEBOOLDS,g); theCommands.Add("voxelfusecolords","voxelfusecolords; returns 0 if success",__FILE__,VOXELFUSECOLORDS,g); theCommands.Add("voxelfusefloatds","voxelfusefloatds; returns 0 if success",__FILE__,VOXELFUSEFLOATDS,g); theCommands.Add("voxelcutboolds","voxelcutboolds; returns 0 if success",__FILE__,VOXELCUTBOOLDS,g); theCommands.Add("voxelcutcolords","voxelcutcolords; returns 0 if success",__FILE__,VOXELCUTCOLORDS,g); theCommands.Add("voxelcutfloatds","voxelcutfloatds; returns 0 if success",__FILE__,VOXELCUTFLOATDS,g); }