static AcBr::ErrorStatus
faceToNurbSurface(AcBrFace& faceEntity)
{ 
    AcBr::ErrorStatus returnValue = AcBr::eOk;

	// This is the face-bounded surface converted to a NURB.
	double fitTol = 0.0;

	AcGeNurbSurface surfaceGeometry;
    double fitTolRequired = 0.0;

    returnValue = faceEntity.getSurfaceAsNurb(surfaceGeometry, &fitTolRequired, &fitTol);
	if (returnValue != AcBr::eOk) {
		acutPrintf(ACRX_T("\n Error in AcBrFace::getSurfaceAsNurb:"));
    	errorReport(returnValue);
        return returnValue;
	}

	acutPrintf(ACRX_T("\nSurface As Bounded Nurb\n"));
	acutPrintf(ACRX_T("\n*Surface fit tolerance is %lf\n"), fitTol);
	
	acutPrintf(ACRX_T("\n**NURB Surface Definition Data begin:\n"));
	acutPrintf(ACRX_T("\n**NURB Surface degree in U is %d\n"), surfaceGeometry.degreeInU());
	acutPrintf(ACRX_T("\n**NURB Surface degree in V is %d\n"), surfaceGeometry.degreeInV());
	acutPrintf(ACRX_T("\n**NURB Surface number of control points in U is %d\n"), 
		surfaceGeometry.numControlPointsInU());
	acutPrintf(ACRX_T("\n**NURB Surface number of control points in V is %d\n"), 
		surfaceGeometry.numControlPointsInV());
	acutPrintf(ACRX_T("\n**NURB Surface number of knots in U is %d\n"), 
		surfaceGeometry.numKnotsInU());
	acutPrintf(ACRX_T("\n**NURB Surface number of knots in V is %d\n"), 
		surfaceGeometry.numKnotsInV());
	acutPrintf(ACRX_T("\n*NURB Surface Definition Data End\n"));

	// make a face loop traverser to access the surface boundary
	AcBrFaceLoopTraverser faceLoopTrav;
	returnValue = faceLoopTrav.setFace(faceEntity);
	if (returnValue != AcBr::eOk) {
        // eDegenerateTopology means intrinsically bounded (e.g., sphere, torus)  
		if (returnValue != AcBr::eDegenerateTopology) {
		    acutPrintf(ACRX_T("\n Error in AcBrFaceLoopTraverser::setFace:")); 
			errorReport(returnValue);
			return returnValue;
        } else {
		    acutPrintf(ACRX_T("\n faceToTrimmedSurface: trimmed data unavailable on intrinsically bounded surfaces\n")); 
			errorReport(returnValue);
			return returnValue;
        }
	} else while (!faceLoopTrav.done() && (returnValue == AcBr::eOk)) { 
    	// make a loop edge traverser to access the trimming data
	    AcBrLoopEdgeTraverser loopEdgeTrav;
    	returnValue = loopEdgeTrav.setLoop(faceLoopTrav);
	    if (returnValue != AcBr::eOk) {	 
            // eDegenerateTopology means loop vertex (special case and go to next loop) 
        	if (returnValue != AcBr::eDegenerateTopology) {
			    acutPrintf(ACRX_T("\n Error in AcBrLoopEdgeTraverser::setLoop:")); 
    		    errorReport(returnValue);
    		    return returnValue;
			} else {
				AcBrLoopVertexTraverser loopVertexTrav;
				returnValue = loopVertexTrav.setLoop(faceLoopTrav);
				if (returnValue != AcBr::eOk) {
					acutPrintf(ACRX_T("\n Error in AcBrLoopVertexTraverser::setLoop:"));
					errorReport(returnValue);
					return returnValue;
				} else {
					AcBrVertex loopVertex;
					returnValue = loopVertexTrav.getVertex(loopVertex);
					if (returnValue != AcBr::eOk) {
						acutPrintf(ACRX_T("\n Error in AcBrLoopVertexTraverser::getVertex:"));
						errorReport(returnValue);
						return returnValue;
					}

					AcGePoint3d pointGeometry;
					returnValue = loopVertex.getPoint(pointGeometry);
				    if (returnValue != AcBr::eOk) {
						acutPrintf(ACRX_T("\n Error in AcBrVertex::getPoint:"));
						errorReport(returnValue);
						return returnValue;
					}
                	acutPrintf(ACRX_T("\n*** Coordinates (x,y,z) at loop vertex: "));
					acutPrintf(ACRX_T("%lf,%lf,%lf\n"), pointGeometry.x, pointGeometry.y,
						pointGeometry.z);

					AcGePoint2d ppointGeometry;
					returnValue = loopVertexTrav.getParamPoint(ppointGeometry);
				    if (returnValue != AcBr::eOk) {
						acutPrintf(ACRX_T("\n Error in AcBrLoopVertexTraverser::getParamPoint:"));
						errorReport(returnValue);
						return returnValue;
					}
                	acutPrintf(ACRX_T("\n*** Parameters (u,v) at loop vertex: "));
					acutPrintf(ACRX_T("%lf,%lf\n"), ppointGeometry.x, ppointGeometry.y);
				} // end loop vertex
			}
	    } else while (!loopEdgeTrav.done() && (returnValue == AcBr::eOk)) { 
			int i, nCtrlPts, nKnots, nWeights;
			
			// Dump the model space NURB curve data
			AcGeNurbCurve3d curveGeometry;
			returnValue = loopEdgeTrav.getOrientedCurveAsNurb(curveGeometry, 0.0, fitTol);  
			if (returnValue != AcBr::eOk) {
				acutPrintf(ACRX_T("\n Error in AcBrLoopEdgeTraverser::getOrientedCurveAsNurb:"));
    			errorReport(returnValue);
				return returnValue;
		    }

			acutPrintf(ACRX_T("\n3D NURB Curve fit tolerance is %lf\n"), fitTol);

			acutPrintf(ACRX_T("\n **3D NURB Curve of degree %d and order %d\n"),
			    curveGeometry.degree(), curveGeometry.order());

			nCtrlPts = curveGeometry.numControlPoints();
			acutPrintf(ACRX_T("\n **3D NURB Curve has %d control points\n"), nCtrlPts);
			for(i=0; i<nCtrlPts; i++) {
				acutPrintf(ACRX_T("\n ***Control point [%d] (%lf, %lf, %lf)\n"), i,
					curveGeometry.controlPointAt(i).x,
					curveGeometry.controlPointAt(i).y,
					curveGeometry.controlPointAt(i).z);
			}

			nKnots = curveGeometry.numKnots();
		   	acutPrintf(ACRX_T("\n **3D NURB Curve has %d knots\n"), nKnots);
		   	for (i=0; i<nKnots; i++) {
				acutPrintf(ACRX_T("\n ***Knot [%d] %lf\n"), i,
					curveGeometry.knotAt(i));
			}

			nWeights = curveGeometry.numWeights();
			acutPrintf(ACRX_T("\n **3D NURB Curve has %d weights\n"), nWeights);
			for (i=0; i<nWeights; i++) {
				acutPrintf(ACRX_T("\n ***Weight [%d] %lf)\n"), i,
					curveGeometry.weightAt(i));
			}	  

			AcGePoint3d pt1, pt2;
			if (curveGeometry.hasStartPoint(pt1)) {
				acutPrintf(ACRX_T("\n **3D NURB Curve start point is("));
    			acutPrintf (ACRX_T("%lf , "), pt1.x);	
    			acutPrintf (ACRX_T("%lf , "), pt1.y);
    			acutPrintf (ACRX_T("%lf "), pt1.z);
    			acutPrintf(ACRX_T(")\n"));	
			}
			if (curveGeometry.hasEndPoint(pt2)) {
				acutPrintf(ACRX_T("\n **3D NURB Curve end point is("));
    			acutPrintf (ACRX_T("%lf , "), pt2.x);	
    			acutPrintf (ACRX_T("%lf , "), pt2.y);
    			acutPrintf (ACRX_T("%lf "), pt2.z);
    			acutPrintf(ACRX_T(")\n"));	
			}

			// Dump the parameter space NURB curve data
			AcGeNurbCurve2d pcurveGeometry;
			returnValue = loopEdgeTrav.getParamCurveAsNurb(pcurveGeometry, 0.0, fitTol);  
			if (returnValue != AcBr::eOk) {
				acutPrintf(ACRX_T("\n Error in AcBrLoopEdgeTraverser::getParamCurveAsNurb:"));
    			errorReport(returnValue);
				return returnValue;
		    }

			acutPrintf(ACRX_T("\n2D NURB Curve fit tolerance is %lf\n"), fitTol);

			acutPrintf(ACRX_T("\n **2D NURB Curve of degree %d and order %d\n"),
			    pcurveGeometry.degree(), pcurveGeometry.order());

			nCtrlPts = pcurveGeometry.numControlPoints();
			acutPrintf(ACRX_T("\n **2D NURB Curve has %d control points\n"), nCtrlPts);
			for(i=0; i<nCtrlPts; i++) {
				acutPrintf(ACRX_T("\n ***Control point [%d] (%lf, %lf)\n"), i,
					pcurveGeometry.controlPointAt(i).x,
					pcurveGeometry.controlPointAt(i).y);
			}

			nKnots = pcurveGeometry.numKnots();
		   	acutPrintf(ACRX_T("\n **2D NURB Curve has %d knots\n"), nKnots);
		   	for (i=0; i<nKnots; i++) {
				acutPrintf(ACRX_T("\n ***Knot [%d] %lf\n"), i,
					pcurveGeometry.knotAt(i));
			}

			nWeights = pcurveGeometry.numWeights();
			acutPrintf(ACRX_T("\n **2D NURB Curve has %d weights\n"), nWeights);
			for (i=0; i<nWeights; i++) {
				acutPrintf(ACRX_T("\n ***Weight [%d] %lf)\n"), i,
					pcurveGeometry.weightAt(i));
			}	  

			returnValue = loopEdgeTrav.next();
		    if (returnValue != AcBr::eOk) {
			    acutPrintf(ACRX_T("\n Error in AcBrLoopEdgeTraverser::next:"));
			    errorReport(returnValue);
			    return returnValue;
	    	}
	    } // end edge while

    	returnValue = faceLoopTrav.next();
    	if (returnValue != AcBr::eOk) {
	    	acutPrintf(ACRX_T("\n Error in AcBrFaceLoopTraverser::next:"));
		    errorReport(returnValue);
		    return returnValue;
	    }
	} // end loop while

    return returnValue;
}
Пример #2
0
static AcBr::ErrorStatus
brepDumpDown(const AcBrBrep& brepEntity)
{ 
    AcBr::ErrorStatus returnValue = AcBr::eOk;

	// make a global complex traverser
	AcBrBrepComplexTraverser brepComplexTrav;
	returnValue = brepComplexTrav.setBrep(brepEntity);
	if (returnValue != AcBr::eOk) {
		acutPrintf("\n Error in AcBrBrepComplexTraverser::setBrep:");
		errorReport(returnValue);
		return returnValue;
	}

	// dump the complexes
	int complexCount = 0;
	while (!brepComplexTrav.done() && (returnValue == AcBr::eOk)) {
	    complexCount++;
	    acutPrintf("\n *Complex No: %d \n", complexCount);

		// make a complex shell traverser
		AcBrComplexShellTraverser complexShellTrav;
		returnValue = complexShellTrav.setComplex(brepComplexTrav);
		if (returnValue != AcBr::eOk) {
			acutPrintf("\n Error in AcBrComplexShellTraverser::setComplex:");
			errorReport(returnValue);
			return returnValue;
		}

		// dump the shells
		int shellCount = 0;
		while (!complexShellTrav.done() && (returnValue == AcBr::eOk)) {
			shellCount++;
			acutPrintf("\n **Shell No: %d \n", shellCount);

			AcBrShell shell;
			returnValue = complexShellTrav.getShell(shell);
			 if (returnValue != AcBr::eOk) {	
				acutPrintf("\n Error in AcBrComplexShellTraverser::getShell:"); 
				errorReport(returnValue);
				return returnValue;
			}
			AcBr::ShellType stype;
			shell.getType(stype);
			shellTypeReport(stype);

			// make a shell face traverser
			AcBrShellFaceTraverser shellFaceTrav;
			returnValue = shellFaceTrav.setShell(complexShellTrav);
			if (returnValue != AcBr::eOk) {
				acutPrintf("\n Error in AcBrShellFaceTraverser::setShell:");
				errorReport(returnValue);
				return returnValue;
			}

			// count the faces
			int faceCount = 0;
			while (!shellFaceTrav.done() && (returnValue == AcBr::eOk)) {
				faceCount++;
				acutPrintf("\n ***Face No: %d \n", faceCount);

				AcBrFace currentFace;
				returnValue = shellFaceTrav.getFace(currentFace);
				if (returnValue != AcBr::eOk) {
					acutPrintf("\n Error in AcBrShellFaceTraverser::getFace:");
					errorReport(returnValue);
					return returnValue;
				}

    			// make sure that comparing different types returns kFalse
				// rather than crashing!
				if (currentFace.isEqualTo(&brepEntity)) {
					acutPrintf("\n Brep and face have the same contents (impossible!)");
					return (AcBr::ErrorStatus)eAmbiguousOutput;
				}

				int loopCount = 0;
				AcBrFaceLoopTraverser faceLoopTrav;
				returnValue = faceLoopTrav.setFace(shellFaceTrav);
				if (returnValue != AcBr::eOk) {
					// eDegenerateTopology means intrinsically bounded (e.g., sphere, torus)  
					if (returnValue != AcBr::eDegenerateTopology) {
						acutPrintf("\n Error in AcBrFaceLoopTraverser::setFace:"); 
						errorReport(returnValue);
						return returnValue;
					} else returnValue = AcBr::eOk;
				} else while (!faceLoopTrav.done() && (returnValue == AcBr::eOk)) { 
					loopCount++;
					acutPrintf("\n ****Loop No: %d \n", loopCount);

					AcBrLoop loop;
					returnValue = faceLoopTrav.getLoop(loop);
					 if (returnValue != AcBr::eOk) {	
						acutPrintf("\n Error in AcBrFaceLoopTraverser::getLoop:"); 
						errorReport(returnValue);
						return returnValue;
					}
					AcBr::LoopType ltype;
					loop.getType(ltype);
					loopTypeReport(ltype);

					int edgeCount = 0;
					AcBrLoopEdgeTraverser loopEdgeTrav;
	    			returnValue = loopEdgeTrav.setLoop(faceLoopTrav);
					if ((returnValue != AcBr::eOk) && (returnValue != AcBr::eDegenerateTopology)) {	 
						// eDegenerateTopology means this edge is a singularity (loop-vertex)
						acutPrintf("\n Error in AcBrLoopEdgeTraverser::setLoop:"); 
						errorReport(returnValue);
						return returnValue;
					} else while (!loopEdgeTrav.done() && (returnValue == AcBr::eOk)) { 
						edgeCount++; 
						acutPrintf("\n *****Edge No: %d \n", edgeCount);

						AcBrEdge edgeEntity;
						returnValue = loopEdgeTrav.getEdge(edgeEntity);
						if (returnValue != AcBr::eOk) {
							acutPrintf("\n Error in AcBrLoopEdgeTraverser::getEdge:");
							errorReport(returnValue);
							return returnValue;
						}

    					// validate the 3d model space curve associated with this edge
            			AcGeCurve3d* curveGeometry = NULL;
						AcGeCurve3d* nativeGeometry = NULL;

            			returnValue = getNativeOrientedCurve(loopEdgeTrav, curveGeometry, nativeGeometry);  
            			if (returnValue != AcBr::eOk) {
            				acutPrintf("\n Error in getNativeOrientedCurve:");
            				errorReport(returnValue);
							delete curveGeometry;
							delete nativeGeometry;
							return returnValue;
            			}
				
    					// validate the 2d parameter space curve associated with this edge
    					AcGeCurve2d* pcurveGeometry =  NULL;
    					AcGeNurbCurve2d nurbGeometry;
    					returnValue = getNativeParamCurve(loopEdgeTrav, pcurveGeometry, nurbGeometry);
    					if (returnValue != AcBr::eOk) {
    						acutPrintf("\n Error in getNativeParamCurve:");
    						errorReport(returnValue);
							delete pcurveGeometry;
							return returnValue;
    					}
						if (pcurveGeometry != NULL) {
							// Determine if the model space curve and parameter space curve
							// agree in their orientation (2d curves are presented in loop perspective)
            				AcGeInterval crvIntrvl;
            				((AcGeExternalCurve3d*)curveGeometry)->getInterval(crvIntrvl);
            				AcGeInterval pcrvIntrvl;
            				((AcGeExternalCurve2d*)pcurveGeometry)->getInterval(pcrvIntrvl);
							if (crvIntrvl != pcrvIntrvl) {
								if ((crvIntrvl.upperBound() == -pcrvIntrvl.lowerBound())
									&& (crvIntrvl.lowerBound() == -pcrvIntrvl.upperBound())) {
                					acutPrintf("\n ******Edge No. %d: Curve and Pcurve Orientations Oppose\n",
                						edgeCount);
								} else {
                					acutPrintf("\n ******Edge No. %d: Curve and Pcurve Parameter Bounds Differ\n",
                						edgeCount);
                					acutPrintf(" *******Curve Parameterisation is (");
									acutPrintf("%lf, ", crvIntrvl.lowerBound());
									acutPrintf("%lf ", crvIntrvl.upperBound());
									acutPrintf(")\n");
                					acutPrintf(" *******Parameter Curve Parameterisation is (");
									acutPrintf("%lf, ", pcrvIntrvl.lowerBound());
									acutPrintf("%lf ", pcrvIntrvl.upperBound());
									acutPrintf(")\n");
								}
							}
						}
						delete pcurveGeometry;
						delete curveGeometry;
						delete nativeGeometry;

						// Inform of any negated orientations, since the model space curve
						// is returned as is (no curve reversal for usage by surface boundary)
            			Adesk::Boolean edgeOriented, loopOriented;
            			returnValue = loopEdgeTrav.getEdgeOrientToLoop(loopOriented);
            			if (returnValue != AcBr::eOk) {
            				acutPrintf("\n Error in AcBrLoopEdgeTraverser::getEdgeOrientToLoop:");
							errorReport(returnValue);
            				return returnValue;
            			} 
            			returnValue = edgeEntity.getOrientToCurve(edgeOriented);
            			if (returnValue != AcBr::eOk) {
            				acutPrintf("\n Error in AcBrEdge::getOrientToCurve:");
							errorReport(returnValue);
            				return returnValue;
            			} 
            			if (!loopOriented ^ !edgeOriented) {
            				acutPrintf("\n ******Edge No. %d: Curve Orientation in Loop is Negative\n",
            					edgeCount);
            			}

						returnValue = loopEdgeTrav.next();
						if (returnValue != AcBr::eOk) {
							acutPrintf("\n Error in AcBrLoopEdgeTraverser::next:");
							errorReport(returnValue);
							return returnValue;
		    			}
					} // end edge while

					acutPrintf("\n *****Loop No. %d has %d edges\n", loopCount, edgeCount);	  

					int vtxCount = 0;
					AcBrLoopVertexTraverser loopVtxTrav;
	    			returnValue = loopVtxTrav.setLoop(faceLoopTrav);
					if (returnValue != AcBr::eOk) {	 
						acutPrintf("\n Error in AcBrLoopVertexTraverser::setLoop:"); 
						errorReport(returnValue);
						return returnValue;
					} else while (!loopVtxTrav.done() && (returnValue == AcBr::eOk)) { 
						vtxCount++; 
						acutPrintf("\n *****Vertex No: %d \n", vtxCount);

						AcBrVertex loopPoint;
						returnValue = loopVtxTrav.getVertex(loopPoint);
						if (returnValue != AcBr::eOk) {
							acutPrintf("\n Error in AcBrLoopVertexTraverser::getVertex:");
							errorReport(returnValue);
							return returnValue;
						}
						acutPrintf("\nCoordinate of loop vertex: ");
						returnValue = vertexDump(loopPoint);
						if (returnValue != AcBr::eOk) {
							acutPrintf("\n Error in vertexDump:");
							errorReport(returnValue);
							return returnValue;
						}
						
						returnValue = loopVtxTrav.next();
						if (returnValue != AcBr::eOk) {
							acutPrintf("\n Error in AcBrLoopVertexTraverser::next:");
							errorReport(returnValue);
							return returnValue;
		    			}
					} // end vertex while

					acutPrintf("\n *****Loop No. %d has %d vertices\n", loopCount, vtxCount);	  

					returnValue = faceLoopTrav.next();
	    			if (returnValue != AcBr::eOk) {
		    			acutPrintf("\n Error in AcBrFaceLoopTraverser::next:");
						errorReport(returnValue);
						return returnValue;
					}
    			} // end loop while

				acutPrintf("\n ****Face No. %d has %d loops\n", faceCount, loopCount);	  

				returnValue = shellFaceTrav.next();
				if (returnValue != AcBr::eOk) {
					acutPrintf("\n Error in AcBrShellFaceTraverser::next:");  
					errorReport(returnValue);
					return returnValue;
				}

			} // end face while

			acutPrintf("\n ***Shell No. %d has %d faces\n", shellCount, faceCount);	  

			returnValue = complexShellTrav.next();
			if (returnValue != AcBr::eOk) {
				acutPrintf("\n Error in AcBrComplexShellTraverser::next:");  
				errorReport(returnValue);
				return returnValue;
			}

		} // end shell while

		acutPrintf("\n **Complex No. %d has %d shells\n", complexCount, shellCount);	  

		returnValue = brepComplexTrav.next();
		if (returnValue != AcBr::eOk) {
			acutPrintf("\n Error in AcBrBrepComplexTraverser::next:");  
			errorReport(returnValue);
			return returnValue;
		}

	} // end complex while

	acutPrintf("\n *Brep has %d complexes\n", complexCount);	  

	return returnValue;
}