Changeset 732 for cpp/frams/_demos/geometry
- Timestamp:
- 02/15/18 00:42:07 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/geometry/geometrytestutils.cpp
r662 r732 18 18 long count = 0; 19 19 long totalSize = 0; 20 MiniGenotypeLoader loader(file);21 MiniGenotype*genotype;22 20 GenotypeMiniLoader loader(file); 21 GenotypeMini *genotype; 22 23 23 while (genotype = loader.loadNextGenotype()) 24 24 { 25 25 count++; 26 26 totalSize += genotype->genotype.len(); 27 27 28 28 fprintf(stderr, "%d. (%6d chars) %s\n", count, genotype->genotype.len(), 29 29 genotype->name.c_str()); 30 30 } 31 32 if (loader.getStatus() == MiniGenotypeLoader::OnError)31 32 if (loader.getStatus() == GenotypeMiniLoader::OnError) 33 33 { 34 34 fprintf(stderr, "Error: %s\n", loader.getError().c_str()); … … 44 44 class TestInvoker 45 45 { 46 47 46 public: 47 virtual void operator()(Model &model) = 0; 48 48 }; 49 49 … … 53 53 const int genoIndex = isdigit(genoId[0]) ? atol(genoId) : 0; 54 54 long count = 0; 55 MiniGenotypeLoader loader(file);56 MiniGenotype*genotype;57 55 GenotypeMiniLoader loader(file); 56 GenotypeMini *genotype; 57 58 58 while (genotype = loader.loadNextGenotype()) 59 59 { 60 60 count++; 61 61 62 62 if ((genoIndex == count) || (strcmp(genotype->name.c_str(), genoName) == 0)) 63 63 { 64 64 Model model(genotype->genotype); 65 65 66 66 if (!model.isValid()) 67 67 { … … 74 74 } 75 75 } 76 77 if (loader.getStatus() == MiniGenotypeLoader::OnError)76 77 if (loader.getStatus() == GenotypeMiniLoader::OnError) 78 78 { 79 79 fprintf(stderr, "Error: %s\n", loader.getError().c_str()); … … 94 94 if ((shape < 1) || (shape > 3)) 95 95 { 96 shape = (rand() %3) + 1;96 shape = (rand() % 3) + 1; 97 97 } 98 98 … … 106 106 } 107 107 108 class ModelBasedTestInvoker : public TestInvoker109 { 110 111 void(*test)(Model &);112 113 ModelBasedTestInvoker(void (*_test)(Model &)):114 115 116 117 118 119 108 class ModelBasedTestInvoker : public TestInvoker 109 { 110 private: 111 void(*test)(Model &); 112 public: 113 ModelBasedTestInvoker(void(*_test)(Model &)) : 114 test(_test) 115 {} 116 void operator()(Model &model) 117 { 118 test(model); 119 } 120 120 }; 121 121 122 int GeometryTestUtils::execute(const SString header, int argc, char *argv[], void 122 int GeometryTestUtils::execute(const SString header, int argc, char *argv[], void(*test)(Model &)) 123 123 { 124 124 LoggerToStdout messages_to_stdout(LoggerBase::Enable); //comment this object out to mute error/warning messages 125 125 StdioFileSystem_autoselect stdiofilesys; 126 126 PreconfiguredGenetics genetics; 127 127 128 128 srand(time(NULL)); 129 129 … … 132 132 return printGenotypesList(argv[2]); 133 133 } 134 134 135 135 if ((argc == 4) && (strcmp("-l", argv[1]) == 0)) 136 136 { … … 138 138 return executeTestUsingLoadedModel(argv[2], argv[3], invoker); 139 139 } 140 140 141 141 if ((argc == 2) && (strcmp("-c", argv[1]) == 0)) 142 142 { … … 144 144 return executeTestUsingRandomModel(-1, invoker); 145 145 } 146 146 147 147 if ((argc == 3) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0])) 148 148 { … … 151 151 return executeTestUsingRandomModel(shape, invoker); 152 152 } 153 153 154 154 fprintf(stderr, 155 155 "%s\n\n" … … 165 165 } 166 166 167 class ModelAndDensityBasedTestInvoker : public TestInvoker168 { 169 170 void(*test)(Model &, const double);171 172 173 ModelAndDensityBasedTestInvoker(void (*_test)(Model &, const double), double _density):174 175 176 177 178 179 180 181 167 class ModelAndDensityBasedTestInvoker : public TestInvoker 168 { 169 private: 170 void(*test)(Model &, const double); 171 double density; 172 public: 173 ModelAndDensityBasedTestInvoker(void(*_test)(Model &, const double), double _density) : 174 test(_test), 175 density(_density) 176 {} 177 178 void operator()(Model &model) 179 { 180 test(model, density); 181 } 182 182 }; 183 183 184 184 int GeometryTestUtils::execute(const SString header, int argc, char *argv[], 185 void 185 void(*test)(Model &, const double)) 186 186 { 187 187 LoggerToStdout messages_to_stdout(LoggerBase::Enable); //comment this object out to mute error/warning messages 188 188 StdioFileSystem_autoselect stdiofilesys; 189 189 PreconfiguredGenetics genetics; 190 190 191 191 srand(time(NULL)); 192 192 … … 202 202 return executeTestUsingLoadedModel(argv[2], argv[3], invoker); 203 203 } 204 204 205 205 if ((argc == 3) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0])) 206 206 { … … 209 209 return executeTestUsingRandomModel(-1, invoker); 210 210 } 211 211 212 212 if ((argc == 4) && (strcmp("-c", argv[1]) == 0) && isdigit(argv[2][0]) && isdigit(argv[3][0])) 213 213 { … … 217 217 return executeTestUsingRandomModel(shape, invoker); 218 218 } 219 219 220 220 fprintf(stderr, 221 221 "%s\n\n" … … 235 235 { 236 236 Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID); 237 237 238 238 part->p = Pt3D(0); 239 239 part->scale = Pt3D(0.1); 240 240 part->vcolor = Pt3D(1.0, 0.0, 1.0); 241 241 242 242 addAxesToModel(Pt3D(0.5), Orient(Orient_1), Pt3D(0.0), model); 243 243 } … … 247 247 Part *anchor = model.getPart(0); 248 248 Part *part = model.addNewPart(Part::SHAPE_ELLIPSOID); 249 249 250 250 part->p = Pt3D(markerLocation); 251 251 part->scale = Pt3D(0.05); 252 252 part->vcolor = Pt3D(1.0, 1.0, 0.0); 253 253 254 254 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 255 255 } … … 260 260 Part *anchor = model.getPart(0); 261 261 Part *part; 262 262 263 263 part = model.addNewPart(Part::SHAPE_CUBOID); 264 264 part->scale = Pt3D(sizes.x, 0.05, 0.05); … … 267 267 part->vcolor = Pt3D(1.0, 0.0, 0.0); 268 268 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 269 269 270 270 part = model.addNewPart(Part::SHAPE_CUBOID); 271 271 part->scale = Pt3D(0.05, sizes.y, 0.05); … … 274 274 part->vcolor = Pt3D(0.0, 1.0, 0.0); 275 275 model.addNewJoint(anchor, part, Joint::SHAPE_FIXED); 276 276 277 277 part = model.addNewPart(Part::SHAPE_CUBOID); 278 278 part->scale = Pt3D(0.05, 0.05, sizes.z); … … 287 287 Part *targetAnchor = target.getPart(0); 288 288 Part *sourceAnchor = source.getPart(0); 289 289 290 290 target.moveElementsFrom(source); 291 291 292 292 target.addNewJoint(targetAnchor, sourceAnchor, Joint::SHAPE_FIXED); 293 293 } … … 295 295 double frand(double from, double width) 296 296 { 297 return from + width * ((rand() %10000) / 10000.0);297 return from + width * ((rand() % 10000) / 10000.0); 298 298 } 299 299
Note: See TracChangeset
for help on using the changeset viewer.