[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43296] branches/carve_booleans/intern/ boolop/intern/BOP_CarveInterface.cpp: Carve booleans: code style cleanup

Sergey Sharybin sergey.vfx at gmail.com
Wed Jan 11 15:43:35 CET 2012


Revision: 43296
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43296
Author:   nazgul
Date:     2012-01-11 14:43:34 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
Carve booleans: code style cleanup

Modified Paths:
--------------
    branches/carve_booleans/intern/boolop/intern/BOP_CarveInterface.cpp

Modified: branches/carve_booleans/intern/boolop/intern/BOP_CarveInterface.cpp
===================================================================
--- branches/carve_booleans/intern/boolop/intern/BOP_CarveInterface.cpp	2012-01-11 14:43:20 UTC (rev 43295)
+++ branches/carve_booleans/intern/boolop/intern/BOP_CarveInterface.cpp	2012-01-11 14:43:34 UTC (rev 43296)
@@ -61,18 +61,19 @@
 	return 1;
 }
 
-static carve::mesh::MeshSet<3> *Carve_addMesh(
-				 CSG_FaceIteratorDescriptor& face_it,
-				 CSG_VertexIteratorDescriptor& vertex_it,
-				 carve::interpolate::FaceAttr<uint> &oface_num,
-				 uint &num_origfaces )
+static carve::mesh::MeshSet<3> *Carve_addMesh(CSG_FaceIteratorDescriptor& face_it,
+                                              CSG_VertexIteratorDescriptor& vertex_it,
+                                              carve::interpolate::FaceAttr<uint> &oface_num,
+                                              uint &num_origfaces )
 {
 	CSG_IVertex vertex;
 	std::vector<carve::geom3d::Vector> vertices;
 
 	while (!vertex_it.Done(vertex_it.it)) {
 		vertex_it.Fill(vertex_it.it,&vertex);
-		vertices.push_back(carve::geom::VECTOR(vertex.position[0], vertex.position[1], vertex.position[2]));
+		vertices.push_back(carve::geom::VECTOR(vertex.position[0],
+		                                       vertex.position[1],
+		                                       vertex.position[2]));
 		vertex_it.Step(vertex_it.it);
 	}
 
@@ -127,7 +128,7 @@
 
 	carve::mesh::MeshSet<3> *poly = new carve::mesh::MeshSet<3> (vertices, numfaces, f);
 
-	unsigned int i;
+	uint i;
 	carve::mesh::MeshSet<3>::face_iter face_iter = poly->faceBegin();
 	for (i = 0; face_iter != poly->faceEnd(); ++face_iter, ++i) {
 		carve::mesh::MeshSet<3>::face_t *face = *face_iter;
@@ -138,9 +139,9 @@
 }
 
 // check whether two faces share an edge, and if so merge them
-static uint quadMerge(std::map<carve::mesh::MeshSet<3>::vertex_t*, unsigned int> *vertexToIndex_map,
-	carve::mesh::MeshSet<3>::face_t *f1, carve::mesh::MeshSet<3>::face_t *f2, uint v,
-	uint quad[4] )
+static uint quadMerge(std::map<carve::mesh::MeshSet<3>::vertex_t*, uint> *vertexToIndex_map,
+                      carve::mesh::MeshSet<3>::face_t *f1, carve::mesh::MeshSet<3>::face_t *f2,
+                      uint v, uint quad[4])
 {
 	uint current, n1, p1, n2, p2;
 	uint v1[3];
@@ -157,24 +158,25 @@
 
 	// locate the current vertex we're examining, and find the next and
 	// previous vertices based on the face windings
-	if( v1[0] == v ) { current = 0; p1 = 2; n1 = 1; }
-	else if( v1[1] == v ) { current = 1; p1 = 0; n1 = 2; }
-	else { current = 2; p1 = 1; n1 = 0; }
+	if (v1[0] == v) {current = 0; p1 = 2; n1 = 1;}
+	else if (v1[1] == v) {current = 1; p1 = 0; n1 = 2;}
+	else {current = 2; p1 = 1; n1 = 0;}
 
-	if( v2[0] == v ) { p2 = 2; n2 = 1; }
-	else if( v2[1] == v ) { p2 = 0; n2 = 2; }
-	else { p2 = 1; n2 = 0; }
+	if (v2[0] == v) {p2 = 2; n2 = 1;}
+	else if (v2[1] == v) {p2 = 0; n2 = 2;}
+	else {p2 = 1; n2 = 0;}
 
 	// if we find a match, place indices into quad in proper order and return
 	// success code
-	if( v1[p1] == v2[n2] ) {
+	if (v1[p1] == v2[n2]) {
 		quad[0] = v1[current];
 		quad[1] = v1[n1];
 		quad[2] = v1[p1];
 		quad[3] = v2[p2];
 
 		return 1;
-	} else if( v1[n1] == v2[p2] ) {
+	}
+	else if (v1[n1] == v2[p2]) {
 		quad[0] = v1[current];
 		quad[1] = v2[n2];
 		quad[2] = v1[n1];
@@ -186,19 +188,20 @@
 	return 0;
 }
 
-static BSP_CSGMesh* Carve_exportMesh(carve::mesh::MeshSet<3>* &poly,
-				 carve::interpolate::FaceAttr<uint> &oface_num,
-				 uint num_origfaces )
+static BSP_CSGMesh* Carve_exportMesh(carve::mesh::MeshSet<3>* &poly, carve::interpolate::FaceAttr<uint> &oface_num,
+                                     uint num_origfaces)
 {
-	unsigned int i;
+	uint i;
 	BSP_CSGMesh* outputMesh = BSP_CSGMesh::New();
-	if (outputMesh == NULL) return NULL;
 
+	if (outputMesh == NULL)
+		return NULL;
+
 	std::vector<BSP_MVertex>* vertices = new std::vector<BSP_MVertex>;
 
 	outputMesh->SetVertices(vertices);
 
-	std::map<carve::mesh::MeshSet<3>::vertex_t*, unsigned int> vertexToIndex_map;
+	std::map<carve::mesh::MeshSet<3>::vertex_t*, uint> vertexToIndex_map;
 	std::vector<carve::mesh::MeshSet<3>::vertex_t>::iterator it = poly->vertex_storage.begin();
 	for (i = 0; it != poly->vertex_storage.end(); ++i, ++it) {
 		carve::mesh::MeshSet<3>::vertex_t *vertex = &(*it);
@@ -233,10 +236,10 @@
 	std::vector< std::vector<uint> >::const_iterator fii;
 	carve::mesh::MeshSet<3>::mesh_t *mesh = poly->meshes.at(0);
 	uint orig = 0;
-	for( fii=ofaces.begin(); fii!=ofaces.end(); ++fii, ++orig ) {
+	for (fii=ofaces.begin(); fii!=ofaces.end(); ++fii, ++orig) {
 		std::vector<uint> fl = *fii;
 		// go over a single set from an original face
-		while( fl.size() > 0 ) {
+		while (fl.size() > 0) {
 			// remove one new face
 			uint findex = fl.back();
 			fl.pop_back();
@@ -262,41 +265,44 @@
 
 					// if we find the current face, ignore it
 					uint otherf = vi[v][pos2];
-					if ( findex == otherf ) continue;
+					if (findex == otherf)
+						continue;
 
 					carve::mesh::MeshSet<3>::face_t *f2 = mesh->faces.at(otherf);
 
 					// if other face doesn't have the same original face,
 					// ignore it also
 					uint other_orig = oface_num.getAttribute(f2);
-					if ( orig != other_orig ) continue;
+					if (orig != other_orig)
+						continue;
 
 					// if, for some reason, we don't find the other face in
 					// the current set of faces, ignore it
 					uint other_index = 0;
-					while( other_index < fl.size() && fl[other_index] != otherf ) ++other_index;
-					if ( other_index == fl.size() ) continue;
+					while (other_index < fl.size() && fl[other_index] != otherf) ++other_index;
+					if (other_index == fl.size()) continue;
 
 					// see if the faces share an edge
 					result = quadMerge(&vertexToIndex_map, f, f2, v, quadverts);
 					// if faces can be merged, then remove the other face
 					// from the current set
-					if ( result ) {
+					if (result) {
 						uint replace = fl.back();
 						fl.pop_back();
-						if( otherf != replace ) fl[other_index] = replace;
+						if(otherf != replace)
+							fl[other_index] = replace;
 					}
 				}
 			}
 
 			// if we merged faces, use the list of common vertices; otherwise
 			// use the faces's vertices
-			if( result ) {
+			if (result) {
 				// make quat using verts stored in result
-				outFace.m_verts.push_back( quadverts[0] );
-				outFace.m_verts.push_back( quadverts[1] );
-				outFace.m_verts.push_back( quadverts[2] );
-				outFace.m_verts.push_back( quadverts[3] );
+				outFace.m_verts.push_back(quadverts[0]);
+				outFace.m_verts.push_back(quadverts[1]);
+				outFace.m_verts.push_back(quadverts[2]);
+				outFace.m_verts.push_back(quadverts[3]);
 			} else {
 				carve::mesh::MeshSet<3>::face_t::edge_iter_t edge_iter = f->begin();
 				for (; edge_iter != f->end(); ++edge_iter) {
@@ -326,11 +332,11 @@
  * @return operation state: BOP_OK, BOP_NO_SOLID, BOP_ERROR
  */
 BoolOpState BOP_performBooleanOperation(BoolOpType                    opType,
-										BSP_CSGMesh**                 outputMesh,
-										CSG_FaceIteratorDescriptor    obAFaces,
-										CSG_VertexIteratorDescriptor  obAVertices,
-										CSG_FaceIteratorDescriptor    obBFaces,
-										CSG_VertexIteratorDescriptor  obBVertices)
+                                        BSP_CSGMesh**                 outputMesh,
+                                        CSG_FaceIteratorDescriptor    obAFaces,
+                                        CSG_VertexIteratorDescriptor  obAVertices,
+                                        CSG_FaceIteratorDescriptor    obBFaces,
+                                        CSG_VertexIteratorDescriptor  obBVertices)
 {
 	carve::csg::CSG::OP op;
 	carve::mesh::MeshSet<3> *left, *right, *output;
@@ -340,17 +346,17 @@
 	uint num_origfaces = 0;
 
 	switch (opType) {
-	case BOP_UNION:
-		op = carve::csg::CSG::UNION;
-		break;
-	case BOP_INTERSECTION:
-		op = carve::csg::CSG::INTERSECTION;
-		break;
-	case BOP_DIFFERENCE:
-		op = carve::csg::CSG::A_MINUS_B;
-		break;
-	default:
-		return BOP_ERROR;
+		case BOP_UNION:
+			op = carve::csg::CSG::UNION;
+			break;
+		case BOP_INTERSECTION:
+			op = carve::csg::CSG::INTERSECTION;
+			break;
+		case BOP_DIFFERENCE:
+			op = carve::csg::CSG::A_MINUS_B;
+			break;
+		default:
+			return BOP_ERROR;
 	}
 
 	left = Carve_addMesh(obAFaces, obAVertices, oface_num, num_origfaces );
@@ -359,7 +365,7 @@
 	min.x = max.x = left->vertex_storage[0].v.x;
 	min.y = max.y = left->vertex_storage[0].v.y;
 	min.z = max.z = left->vertex_storage[0].v.z;
-	for( unsigned int i = 1; i < left->vertex_storage.size(); ++i ) {
+	for (uint i = 1; i < left->vertex_storage.size(); ++i) {
 		min.x = MIN(min.x,left->vertex_storage[i].v.x);
 		min.y = MIN(min.y,left->vertex_storage[i].v.y);
 		min.z = MIN(min.z,left->vertex_storage[i].v.z);
@@ -367,7 +373,7 @@
 		max.y = MAX(max.y,left->vertex_storage[i].v.y);
 		max.z = MAX(max.z,left->vertex_storage[i].v.z);
 	}
-	for( unsigned int i = 0; i < right->vertex_storage.size(); ++i ) {
+	for (uint i = 0; i < right->vertex_storage.size(); ++i) {
 		min.x = MIN(min.x,right->vertex_storage[i].v.x);
 		min.y = MIN(min.y,right->vertex_storage[i].v.y);
 		min.z = MIN(min.z,right->vertex_storage[i].v.z);




More information about the Bf-blender-cvs mailing list