int MassSpringSystemFromTetMeshConfigFile::GenerateMassSpringSystem(const char * configFilename, MassSpringSystem ** massSpringSystem, MassSpringSystemTetMeshConfiguration * massSpringSystemTetMeshConfiguration) { char tetMeshFilename[4096]; char surfaceMeshFilename[4096]; double density, tensileStiffness, damping; int addGravity; printf("Parsing configuration file %s...\n", configFilename); ConfigFile configFile; configFile.addOption("tetMeshFilename", tetMeshFilename); configFile.addOptionOptional("surfaceMeshFilename", surfaceMeshFilename, "__none"); configFile.addOption("density", &density); configFile.addOption("tensileStiffness", &tensileStiffness); configFile.addOption("damping", &damping); configFile.addOption("addGravity", &addGravity); if (configFile.parseOptions(configFilename) != 0) { printf("Error parsing options.\n"); return 1; } // the config variables have now been loaded with their specified values // informatively print the variables (with assigned values) that were just parsed configFile.printOptions(); TetMesh * tetMesh; try { tetMesh = new TetMesh(tetMeshFilename); } catch(int eCode) { printf("Error: unable to load mesh from %s. Code: %d\n", tetMeshFilename, eCode); return 1; }; printf("Tet mesh loaded.\n"); MassSpringSystemFromTetMesh massSpringSystemFromTetMesh; int code = massSpringSystemFromTetMesh.GenerateMassSpringSystem(tetMesh, massSpringSystem, density, tensileStiffness, damping, addGravity); delete(tetMesh); if (massSpringSystemTetMeshConfiguration != NULL) { massSpringSystemTetMeshConfiguration->tetMeshFilename = DuplicateString(tetMeshFilename); massSpringSystemTetMeshConfiguration->surfaceMeshFilename = DuplicateString(surfaceMeshFilename); massSpringSystemTetMeshConfiguration->density = density; massSpringSystemTetMeshConfiguration->tensileStiffness = tensileStiffness; massSpringSystemTetMeshConfiguration->damping = damping; massSpringSystemTetMeshConfiguration->addGravity = addGravity; } return code; }
void initConfigurations() { ConfigFile configFile; // specify the entries of the config file configFile.addOptionOptional("windowWidth",&windowWidth,800); configFile.addOptionOptional("windowHeight",&windowHeight,800); configFile.addOption("deformableObjectFilename",deformableObjectFilename); configFile.addOptionOptional("modesFilename",modesFilename,"__none"); configFile.addOptionOptional("cubicPolynomialFilename",cubicPolynomialFilename,"__none"); configFile.addOption("dampingMassCoef",&dampingMassCoef); configFile.addOption("dampingStiffnessCoef",&dampingStiffnessCoef); configFile.addOptionOptional("plasticThreshold", &plasticThreshold, plasticThreshold); configFile.addOption("deformableObjectCompliance",&deformableObjectCompliance); configFile.addOption("frequencyScaling",&frequencyScaling); configFile.addOptionOptional("cameraRadius",&cameraRadius,17.5); configFile.addOptionOptional("focusPositionX",&focusPositionX,0.0); configFile.addOptionOptional("focusPositionY",&focusPositionY,0.0); configFile.addOptionOptional("focusPositionZ",&focusPositionZ,0.0); configFile.addOptionOptional("cameraLongitude",&cameraLongitude,-60.0); configFile.addOptionOptional("cameraLattitude",&cameraLattitude,20.0); configFile.addOptionOptional("renderWireframe",&renderWireframe,1); configFile.addOptionOptional("extraSceneGeometry",extraSceneGeometryFilename,"__none"); configFile.addOptionOptional("enableTextures",&enableTextures,enableTextures); configFile.addOptionOptional("backgroundColor",backgroundColorString, backgroundColorString); string lightingConfigFilenameDefault = configFilesDir + "default.lighting"; configFile.addOptionOptional("lightingConfigFilename",lightingConfigFilename, (char*) lightingConfigFilenameDefault.c_str()); configFile.addOptionOptional("substepsPerTimeStep", &substepsPerTimeStep, substepsPerTimeStep); configFile.addOptionOptional("renderOnGPU", &renderOnGPU, 1); // parse the configuration file if (configFile.parseOptions((char*)configFilename.c_str()) != 0) { printf("Error: unable to load the configuration file.\n"); exit(1); } // the config variables have now been loaded with their specified values // informatively print the variables (with assigned values) that were just parsed configFile.printOptions(); }
int MassSpringSystemFromObjMeshConfigFile::GenerateMassSpringSystem(char * configFilename, MassSpringSystem ** massSpringSystem, MassSpringSystemObjMeshConfiguration * massSpringSystemObjConfiguration) { char massSpringMeshFilename[4096]; double surfaceDensity, tensileStiffness, shearStiffness, bendStiffness, damping; int addGravity; printf("Parsing configuration file %s...\n", configFilename); ConfigFile configFile; configFile.addOption("massSpringMeshFilename", massSpringMeshFilename); configFile.addOption("surfaceDensity", &surfaceDensity); configFile.addOption("tensileStiffness", &tensileStiffness); configFile.addOption("shearStiffness", &shearStiffness); configFile.addOption("bendStiffness", &bendStiffness); configFile.addOption("damping", &damping); configFile.addOption("addGravity", &addGravity); if (configFile.parseOptions(configFilename) != 0) { printf("Error parsing options.\n"); return 1; } // the config variables have now been loaded with their specified values // informatively print the variables (with assigned values) that were just parsed configFile.printOptions(); ObjMesh * quadMesh; try { quadMesh = new ObjMesh(massSpringMeshFilename); } catch(int eCode) { printf("Error: unable to load mesh from %s. Code: %d\n", massSpringMeshFilename, eCode); return 1; }; MassSpringSystemFromObjMesh massSpringSystemFromObjMesh; int code = massSpringSystemFromObjMesh.GenerateMassSpringSystem(quadMesh, massSpringSystem, surfaceDensity, tensileStiffness, shearStiffness, bendStiffness, damping, addGravity); delete(quadMesh); if (massSpringSystemObjConfiguration != NULL) { massSpringSystemObjConfiguration->massSpringMeshFilename = DuplicateString(massSpringMeshFilename); massSpringSystemObjConfiguration->surfaceDensity = surfaceDensity; massSpringSystemObjConfiguration->tensileStiffness = tensileStiffness; massSpringSystemObjConfiguration->shearStiffness = shearStiffness; massSpringSystemObjConfiguration->bendStiffness = bendStiffness; massSpringSystemObjConfiguration->damping = damping; massSpringSystemObjConfiguration->addGravity = addGravity; } return code; }
void run() { if (_arguments.count() == 1) { printf("Usage: image_resample <config file path>\n"); return; } ConfigFile config; List<StructuredType::Member> vectorMembers; vectorMembers.add(StructuredType::Member(String("x"), Type::integer)); vectorMembers.add(StructuredType::Member(String("y"), Type::integer)); StructuredType vectorType(String("Vector"), vectorMembers); config.addType(vectorType); config.addOption("inputPicture", Type::string); config.addOption("outputSize", vectorType); config.addOption("subpixels", Type::boolean); config.addOption("tripleResolution", Type::boolean); config.addOption("outputPicture", Type::string); config.load(_arguments[1]); Bitmap<SRGB> input; input.load(File(config.get<String>("inputPicture"))); Bitmap<Vector3<float> > linearInput(input.size()); input.convert(linearInput, ConvertSRGBToLinear()); Array<Any> sizeArray = config.get<List<Any> >("outputSize"); Vector size(sizeArray[0].value<int>(), sizeArray[1].value<int>()); Bitmap<Vector3<float> > linearOutput(size); if (config.get<bool>("subpixels")) linearInput.subPixelResample(&linearOutput, config.get<bool>("tripleResolution")); else linearInput.resample(&linearOutput); Bitmap<SRGB> output(linearOutput.size()); linearOutput.convert(output, ConvertLinearToSRGB()); output.save(File(config.get<String>("outputPicture"))); }