Window::Window(QWidget *parent) : QWidget(parent), ui(new Ui::Window) { QGLFormat qglFormat; qglFormat.setVersion(3, 2); qglFormat.setProfile(QGLFormat::CoreProfile); qglFormat.setSampleBuffers(true); QGLFormat::setDefaultFormat(qglFormat); ui->setupUi(this); // Set the default values. setRadius(DEF_RADIUS); setRestitution(DEF_RESTITUTION); setMass(DEF_MASS); setNumSpheres(0); }
bool SphereLoader::load(const char *filename) { std::string fname = filename; if (!sofa::helper::system::DataRepository.findFile(fname)) return false; char cmd[64]; FILE* file; static const char* SPH_FORMAT = "sph 1.0"; if ((file = fopen(fname.c_str(), "r")) == NULL) { std::cout << "ERROR: cannot read file '" << filename << "'. Exiting..." << std::endl; return false; } // std::cout << "Loading model'" << filename << "'" << std::endl; int totalNumSpheres=0; // Check first line if (fgets(cmd, 7, file) == NULL || !strcmp(cmd,SPH_FORMAT)) { fclose(file); return false; } skipToEOL(file); while (fscanf(file, "%s", cmd) != EOF) { if (!strcmp(cmd,"nums")) { if (fscanf(file, "%d", &totalNumSpheres) == EOF) std::cerr << "Error: SphereLoader: fscanf function has encountered an error." << std::endl; setNumSpheres(totalNumSpheres); } else if (!strcmp(cmd,"sphe")) { int index; double cx=0,cy=0,cz=0,r=1; if (fscanf(file, "%d %lf %lf %lf %lf\n", &index, &cx, &cy, &cz, &r) == EOF) std::cerr << "Error: SphereLoader: fscanf function has encountered an error." << std::endl; addSphere((SReal)cx,(SReal)cy,(SReal)cz,(SReal)r); ++totalNumSpheres; } else if (cmd[0]=='#') { skipToEOL(file); } else // it's an unknown keyword { printf("%s: Unknown Sphere keyword: %s\n", filename, cmd); skipToEOL(file); } } // printf("Model contains %d spheres\n", totalNumSpheres); (void) fclose(file); return true; }