Ejemplo n.º 1
0
    void importModelNoHeader(ParticleModel *model, const embree::FileName &fileName)
    {
      int rc;
      FILE *file = fopen(fileName.c_str(),"r");
      if (!file) 
        throw std::runtime_error("could not open input file "+fileName.str());

      char line[10000]; 
      fgets(line,10000,file); // description line

      int i = 0;
      while (fgets(line,10000,file) && !feof(file)) {
        ++i;
        char atomName[110];
        vec3f p;
        vec3f n;
        rc = sscanf(line,"%100s %f %f %f %f %f %f\n",atomName,
                    &p.x,&p.y,&p.z,
                    &n.x,&n.y,&n.z
                    );
        if (rc != 7 && rc != 4) {
          std::stringstream ss;
          ss << "in " << fileName << " (line " << (i+2) << "): "
             << "could not parse .dat.xyz data line" << std::endl;
          throw std::runtime_error(ss.str());
        }
        int32 type = model->getAtomTypeID(atomName);
        model->type.push_back(type);
        model->position.push_back(p);
      }
    }
Ejemplo n.º 2
0
    void importModel(ParticleModel *model, const embree::FileName &fileName)
    {
      FILE *file = fopen(fileName.c_str(),"r");
      if (!file) 
        throw std::runtime_error("could not open input file "+fileName.str());
      int numAtoms;

      // int rc = sscanf(line,"%i",&numAtoms);
      int rc = fscanf(file,"%i\n",&numAtoms);
      PRINT(numAtoms);
      if (rc != 1) {
        cout << "could not parse .dat.xyz header in input file " << fileName.str() << endl;
        cout << "trying to parse without header..." << endl;
        fclose(file);
        importModelNoHeader(model,fileName);
        return;
      }
      
      char line[10000]; 
      fgets(line,10000,file); // description line

      std::cout << "#" << fileName << " (.dat.xyz format): expecting " << numAtoms << " atoms" << std::endl;
      for (int i=0;i<numAtoms;i++) {
        char atomName[110];
        vec3f p;
        vec3f n;
        if (!fgets(line,10000,file)) {
          std::stringstream ss;
          ss << "in " << fileName << " (line " << (i+2) << "): "
             << "unexpected end of file!?" << std::endl;
          throw std::runtime_error(ss.str());
        }

        rc = sscanf(line,"%100s %f %f %f %f %f %f\n",atomName,
                    &p.x,&p.y,&p.z,
                    &n.x,&n.y,&n.z
                    );
        // rc = fscanf(file,"%100s %f %f %f %f %f %f\n",atomName,
        //             &a.position.x,&a.position.y,&a.position.z,
        //             &n.x,&n.y,&n.z
        //             );
        if (rc != 7 && rc != 4) {
          std::stringstream ss;
          PRINT(rc);
          PRINT(line);
          ss << "in " << fileName << " (line " << (i+2) << "): "
             << "could not parse .dat.xyz data line" << std::endl;
          throw std::runtime_error(ss.str());
        }
        int32 type = model->getAtomTypeID(atomName);
        model->type.push_back(type);
        model->position.push_back(p);
      }
    }
Ejemplo n.º 3
0
    void importTRI(Model &model,
                   const embree::FileName &fileName)
    {
      FILE *file = fopen(fileName.c_str(),"rb");
      if (!file) error("could not open input file");

      int32 numVertices;
      fread(&numVertices,1,sizeof(numVertices),file);

      Mesh *mesh = new Mesh;
      model.mesh.push_back(mesh);

      mesh->position.resize(numVertices);
      mesh->normal.resize(numVertices);
      mesh->triangle.resize(numVertices/3);
      fread(&mesh->position[0],numVertices,4*sizeof(float),file);
      fread(&mesh->normal[0],numVertices,4*sizeof(float),file);
      for (int i=0;i<numVertices/3;i++) {
        mesh->triangle[i].v0 = 3*i+0;
        mesh->triangle[i].v1 = 3*i+1;
        mesh->triangle[i].v2 = 3*i+2;
      }
      model.instance.push_back(Instance(0));
    }