Exemplo n.º 1
0
void SPHSystem::writeFrame(float* c = 0) {
    for (int i = 0; i < n; ++i) {
        Vec x = p[i];
        float ci = c ? c[i] : 0;
        //cout << p[i].x << ' ' << p[i].y << ' '<< p[i].z << ' ' << ci << endl;
        
        logstream.write(reinterpret_cast<const char*>(&x.x), sizeof(float));
        logstream.write(reinterpret_cast<const char*>(&x.y), sizeof(float));
        logstream.write(reinterpret_cast<const char*>(&x.z), sizeof(float));
        logstream.write(reinterpret_cast<const char*>(&ci), sizeof(float));
    }
    
    vector<float> voxels = voxelize(64, 64, 64);
    // write the voxels to a file
    stringstream ss;
    ss << "frame" << curframe << ".bin";
    cout << "writing file " << ss.str() << " with " << voxels.size() << " voxels." << endl;
    ofstream fout(ss.str(), ios::binary);
    fout.write(reinterpret_cast<const char*>(&voxels[0]), sizeof(float)*voxels.size());
    fout.close();
    
    CIsoSurface<float> mc;
    cout << "extracing mesh with marching cubes ..." << endl;
    mc.GenerateSurface(&voxels[0], 1.0f, 63, 63, 63, 1.0, 1.0, 1.0);
    cout << "done." << endl;
    stringstream ss2;
    ss2 << "frame" << curframe << ".obj";
    cout << "writing file " << ss2.str() << endl;
    mc.writeToFile(ss2.str());
}