Пример #1
0
void getCellMesh(voro::voronoicell &_c, ofPoint _pos, ofVboMesh& _mesh, bool bWireframe){
    if( _c.p ) {
        
		if( !bWireframe ) {
			//  Extract Verteces
			//
			ofVboMesh mesh;
			mesh.setMode(OF_PRIMITIVE_TRIANGLES );
			mesh.addVertices(getCellVerteces(_c, _pos));
			
			//  Add triangles using Indeces
			//
			int k,l,m,n;
			for(int i = 1; i < _c.p; i++){
				for(int j = 0; j < _c.nu[i]; j++) {
					
					k = _c.ed[i][j];
					
					if( k >= 0 ) {
						_c.ed[i][j]=-1-k;
						l = _c.cycle_up( _c.ed[i][ _c.nu[i]+j], k);
						m = _c.ed[k][l];
						_c.ed[k][l]=-1-m;
						
						while(m!=i) {
							n = _c.cycle_up( _c.ed[k][ _c.nu[k]+l],m);
							mesh.addTriangle(i, k, m);
							
							k=m;
							l=n;
							m=_c.ed[k][l];
							_c.ed[k][l]=-1-m;
						}
					}
				}
			}
			
			//  Calculate Normals
			//
			_mesh.setMode(OF_PRIMITIVE_TRIANGLES);
			vector<ofMeshFace> faces = mesh.getUniqueFaces();
			for (int i = 0; i < faces.size(); i++) {
				ofMeshFace face = faces[i];
				ofPoint a = face.getVertex(0);
				ofPoint b = face.getVertex(1);
				ofPoint c = face.getVertex(2);
				
				ofPoint normal = ((b - a).cross(c - a)).normalize() * -1.;
				
                
				_mesh.addVertex(a);
				_mesh.addNormal(normal);
				
				_mesh.addVertex(b);
				_mesh.addNormal(normal);
				_mesh.addVertex(c);
				_mesh.addNormal(normal);
                
                // add texture coordinates
                if( i % 2 == 0) {
                    _mesh.addTexCoord(ofVec2f(0.0, 0.0));
                    _mesh.addTexCoord(ofVec2f(0.0, 1.0));
                    _mesh.addTexCoord(ofVec2f(1.0, 0.0));
                } else {
                    _mesh.addTexCoord(ofVec2f(1.0, 0.0));
                    _mesh.addTexCoord(ofVec2f(0.0, 1.0));
                    _mesh.addTexCoord(ofVec2f(1.0, 1.0));
                }
                
                
			}
		} else { // wireframe
			_mesh.setMode(OF_PRIMITIVE_LINES);
			_mesh.addVertices(getCellVerteces(_c, _pos));
			for(int i = 1; i < _c.p; i++){
				for(int j = 0; j < _c.nu[i]; j++) {
					
					int k = _c.ed[i][j];
					
					if( k >= 0 ) {
						_mesh.addIndex(i);
						_mesh.addIndex(k);
					}
				}
			}
		}
    }
}
Пример #2
0
float getCellRadius(voro::voronoicell &_c){
    return pow(3* _c.volume()/4*PI,1.0/3.0);
}
Пример #3
0
ofPoint getCellCentroid(voro::voronoicell &_c, ofPoint _pos ){
    double x,y,z;
    _c.centroid(x,y,z);
    return ofPoint(x,y,z)*0.5 + _pos;
}
void getCellMesh(voro::voronoicell &_c, ofPoint _pos, ofMesh& mesh ){
    if( _c.p ) {
        
        ofPoint centroid = getCellCentroid(_c,_pos);
        
        int i,j,k,l,m,n;
        
        //  Vertex
        //
        double *ptsp=_c.pts;
        vector<ofPoint> vertices;
        vector<ofPoint> normals;
        for(i = 0; i < _c.p; i++, ptsp+=3){
            ofPoint newPoint;
            newPoint.x = _pos.x + ptsp[0]*0.5;
            newPoint.y = _pos.y + ptsp[1]*0.5;
            newPoint.z = _pos.z + ptsp[2]*0.5;
            vertices.push_back(newPoint);
            
            ofPoint newNormal;
            newNormal = _pos - newPoint;//centroid ;
            newNormal = newNormal.normalize();
            normals.push_back(newNormal);
        }
        
//        ofMesh mesh;
        mesh.setMode(OF_PRIMITIVE_TRIANGLES );
        mesh.addVertices(vertices);
        mesh.addNormals(normals);
        
        //  Index
        //
        for(i = 1; i < _c.p; i++){
            for(j = 0; j < _c.nu[i]; j++) {
                
                k = _c.ed[i][j];
                
                if( k >= 0 ) {
                    _c.ed[i][j]=-1-k;
                    l = _c.cycle_up( _c.ed[i][ _c.nu[i]+j], k);
                    m = _c.ed[k][l];
                    _c.ed[k][l]=-1-m;
                    
                    while(m!=i) {
                        n = _c.cycle_up( _c.ed[k][ _c.nu[k]+l],m);
                        mesh.addTriangle(i, k, m);
                        
                        k=m;
                        l=n;
                        m=_c.ed[k][l];
                        _c.ed[k][l]=-1-m;
                    }
                }
            }
        }
        
//        return mesh;
    }
    
//    return ofMesh();
};