CSODistance::~CSODistance() { ML_TRACE_IN("CSODistance::~CSODistance()"); if (_csoList0 != NULL){ _csoList0->removeNotificationObserver(_csoListNotificationCB, this); } ML_DELETE(_outputXMarkerList); // Delete all created CurveData objects while ( !_outputCurveList->getCurveList().empty() ) { ML_DELETE( _outputCurveList->getCurveList().back() ); _outputCurveList->getCurveList().pop_back(); } ML_DELETE( _outputCurveList ); }
void ListModifyProperties::_updateOutputListBase() { ML_TRACE_IN("void ListModifyProperties::_updateOutputListBase()"); ListBase* newOutList = NULL; ListBase* inList = static_cast<ListBase*>(_inListFld->getBaseValue()); if (inList) { const RuntimeType* inListType = inList->getTypeId(); ML_CHECK_RUNTIME_TYPE(inListType); // Create new output list newOutList = static_cast<ListBase*>(inListType->createInstance()); // If instance creation was successful if (newOutList) { MLssize_t insertPos = 0; // Now loop through all input list items for (MLssize_t i = 0; i < static_cast<MLssize_t>(inList->getSize()); i++) { BaseItem* inListItem = inList->getItemAt(i); if (inListItem) { // Nothing to do for BaseItem lists in this version -> just copy lists newOutList->insertItemAt(insertPos, inListItem); insertPos++; } else { ML_PRINT_ERROR("void ListModifyProperties::_updateOutput()", ML_BAD_BASE_FIELD_CONTENT, "Error: An input list contains elements not derived from Base."); } } } else { ML_PRINT_ERROR("void ListModifyProperties::_updateOutput()", ML_BAD_STATE, "Error: Output list could not be created."); } } // if (_inList) handleNotificationOff(); ListBase* oldOutList = static_cast<ListBase*>(_outListFld->getBaseValue()); ML_DELETE(oldOutList); handleNotificationOn(); _outListFld->setBaseValue(newOutList); }
void ListModifyProperties::_deleteOutput() { ML_TRACE_IN("void ListModifyProperties::_deleteOutput()"); ML_TRY { ListBase* outList = static_cast<ListBase*>(_outListFld->getBaseValue()); ML_DELETE(outList); _outListFld->setBaseValue(NULL); } ML_CATCH_RETHROW; }
void ListModifyProperties::_updateOutputListSpecialized() { ML_TRACE_IN("void ListModifyProperties::_updateOutputListBase()"); ListBase* newOutList = NULL; ListBase* inList = static_cast<ListBase*>(_inListFld->getBaseValue()); if (inList) { const RuntimeType* inListType = inList->getTypeId(); ML_CHECK_RUNTIME_TYPE(inListType); MLint changeTypeValue = _changeTypeValueFld->getIntValue(); // Create new output list newOutList = static_cast<ListBase*>(inListType->createInstance()); // If instance creation was successful if (newOutList) { MLssize_t insertPos = 0; // copy list 0: for (MLssize_t i = 0; i < static_cast<MLssize_t>(inList->getSize()); i++) { ItemType* inListItem = static_cast<ItemType*>(inList->getItemAt(i)); ItemType newItem = *inListItem; if (inListItem) { if ( changeTypeValue != 0 ) { newItem.type += (int)changeTypeValue; } newOutList->insertItemAt(insertPos, &newItem); insertPos++; } else { ML_PRINT_ERROR("void ListModifyProperties::_updateOutput()", ML_BAD_BASE_FIELD_CONTENT, "Error: An input list contains elements not derived from Base."); } } } else { ML_PRINT_ERROR("void ListModifyProperties::_updateOutput()", ML_BAD_STATE, "Error: Output list could not be created."); } } // if (_inList) handleNotificationOff(); ListBase* oldOutList = static_cast<ListBase*>(_outListFld->getBaseValue()); ML_DELETE(oldOutList); handleNotificationOn(); _outListFld->setBaseValue(newOutList); }
void CSODistance::_process() { ML_TRACE_IN("void CSODistance::_process()"); _outputXMarkerList->clearList(); // Delete all created CurveData objects while ( !_outputCurveList->getCurveList().empty() ) { ML_DELETE( _outputCurveList->getCurveList().back() ); _outputCurveList->getCurveList().pop_back(); } if (_csoList0 != NULL) { int nCSOs = _csoList0->numCSO(); double minDistance = 0.0; double maxDistance = 0.0; double avgDistance = 0.0; double stdDevDistance = 0.0; std::stringstream distances; distances << _tableHeader << std::endl; switch ( _modeFld->getEnumValue() ){ case FIRST2 : { if ((nCSOs >= 2) && (_csoList0->getCSOAt(0)->getIsFinished()) && (_csoList0->getCSOAt(1)->getIsFinished())) { std::vector<vec3>pointSet1; std::vector<vec3>pointSet2; _csoList0->getCSOAt(0)->fillPathPointCoordinatesFlattened(pointSet1); _csoList0->getCSOAt(1)->fillPathPointCoordinatesFlattened(pointSet2); Vector3 minPoint1,minPoint2,maxPoint1,maxPoint2; MinimalDistancePointClouds* pointSetsMinDist = NULL; ML_CHECK_NEW(pointSetsMinDist, MinimalDistancePointClouds); pointSetsMinDist->setPointSets(pointSet1, pointSet2); pointSetsMinDist->setNumEntries(200); pointSetsMinDist->computeDistance(minPoint1,minPoint2); minDistance = sqrt((minPoint1[0]-minPoint2[0])*(minPoint1[0]-minPoint2[0]) + (minPoint1[1]-minPoint2[1])*(minPoint1[1]-minPoint2[1]) + (minPoint1[2]-minPoint2[2])*(minPoint1[2]-minPoint2[2])); _minimumDistanceFld->setFloatValue( static_cast<float>(minDistance)); _outputXMarkerList->appendItem(XMarker( vec6(minPoint1[0],minPoint1[1],minPoint1[2],0.5f,0.0f,0.0f), vec3(minPoint2[0]-minPoint1[0],minPoint2[1]-minPoint1[1],minPoint2[2]-minPoint1[2]), 0,"")); distances << _csoList0->getCSOAt(0)->getId() << "," << _csoList0->getCSOAt(1)->getId() << "," << minDistance << "," << maxDistance << "," << avgDistance << "," << stdDevDistance << std::endl; } else { _minimumDistancePoint1Fld->setVec3fValue(vec3(0.0,0.0,0.0)); _minimumDistancePoint2Fld->setVec3fValue(vec3(0.0,0.0,0.0)); _minimumDistanceFld->setFloatValue(0.0f); _distancesFld->setStringValue( _tableHeader ); } break; } case INPLANE: case INDEX: { CurveData *outputCurve = new CurveData; double *yValues = new double[ nCSOs ]; double minDist = ML_DOUBLE_MAX; vec3 point1; vec3 point2; double averageMinDistance = 0.0; double averageMeanDistance = 0.0; double averageMaxDistance = 0.0; for ( int iCSO = 0; iCSO<nCSOs; ++iCSO ){ CSO* currentCSO = _csoList0->getCSOAt( iCSO ); CSO* matchingCSO = _findMatchingCSO(iCSO); if (!matchingCSO) {continue;} std::vector<vec3>pointSet1; std::vector<vec3>pointSet2; currentCSO->fillPathPointCoordinatesFlattened(pointSet1); matchingCSO->fillPathPointCoordinatesFlattened(pointSet2); Vector3 minPoint1,minPoint2,maxPoint1,maxPoint2; _getDistances( pointSet1, pointSet2, minDistance,maxDistance,avgDistance,stdDevDistance, minPoint1,minPoint2,maxPoint1,maxPoint2); averageMinDistance += minDistance; averageMeanDistance += avgDistance; averageMaxDistance += maxDistance; distances << currentCSO->getId() << "," << matchingCSO->getId() << "," << minDistance << "," << maxDistance << "," << avgDistance << "," << stdDevDistance << std::endl; if ( minDistance < minDist ){ minDist = minDistance; point1 = minPoint1; point2 = minPoint2; } _outputXMarkerList->appendItem(XMarker( vec6(minPoint1[0],minPoint1[1],minPoint1[2],0.5f,0.0f,0.0f), vec3(minPoint2[0]-minPoint1[0],minPoint2[1]-minPoint1[1],minPoint2[2]-minPoint1[2]), currentCSO->getId(),"")); switch ( _curveStatistic->getEnumValue() ){ case MIN: yValues[ iCSO ] = minDistance; break; case MAX: yValues[ iCSO ] = maxDistance; break; case MEAN: yValues[ iCSO ] = avgDistance; break; case STDEV: yValues[ iCSO ] = stdDevDistance; break; default: break; } } // iCSO averageMinDistance /= (nCSOs != 0 ? nCSOs : 1.0); averageMeanDistance /= (nCSOs != 0 ? nCSOs : 1.0); averageMaxDistance /= (nCSOs != 0 ? nCSOs : 1.0); outputCurve->setY( nCSOs, yValues); delete[] yValues; _outputCurveList->getCurveList().push_back( outputCurve ); _distancesFld->setStringValue( distances.str() ); _minimumDistancePoint1Fld->setVec3fValue(point1); _minimumDistancePoint2Fld->setVec3fValue(point2); _minimumDistanceFld->setFloatValue( static_cast<float>(minDistance) ); _AverageMinimumDistanceFld->setDoubleValue( averageMinDistance ); _AverageMeanDistanceFld->setDoubleValue( averageMeanDistance ); _AverageMaxDistanceFld->setDoubleValue( averageMaxDistance ); break; } default: break; } } else { _minimumDistancePoint1Fld->setVec3fValue(vec3(0.0,0.0,0.0)); _minimumDistancePoint2Fld->setVec3fValue(vec3(0.0,0.0,0.0)); _minimumDistanceFld->setFloatValue(0.0f); _distancesFld->setStringValue( _tableHeader ); } _outputXMarkerListFld->setBaseValue(_outputXMarkerList); _outputCurveListFld->touch(); }
void GraphToFibers::_updateOutput() { _outNodePositions.clearList(); _outNodePositions.selectItemAt(-1); _outEdgePositions.clearList(); _outEdgePositions.selectItemAt(-1); _outEdgeConnections.clearList(); _outEdgeConnections.selectItemAt(-1); int nodeCount = 0; int edgeCount = 0; int currentEdgePositionNum = 0; // Work on a local copy of the graph, because the smoothing will change it Graph* vesselGraph = NULL; ML_CHECK_NEW(vesselGraph, Graph(_inGraph)); vesselGraph->purifyGraph(); //vesselGraph->setRootIdToAllChildren(); vesselGraph->closeSkeletonGaps(); // smooth the graph const int numSmoothingPasses = 3; const float smoothingFactor = 0.7; //const Graph::EdgeIterator endEdge(); for (Graph::EdgeIterator iter = vesselGraph->beginEdge(); iter != vesselGraph->endEdge(); ++iter) { static_cast<VesselEdge*>(*iter)->smooth(numSmoothingPasses, smoothingFactor, smoothingFactor); } // Iterate over all root nodes for (Graph::ConstNodeIterator iter = vesselGraph->beginRoot(); iter != vesselGraph->endRoot(); iter++) { } // Iterate over all nodes for (Graph::ConstNodeIterator i = vesselGraph->beginNode(); i != vesselGraph->endNode(); i++) { const VesselNode* thisNode = *i; const Vector3 thisNodePos = thisNode->getPos(); //thisNode->getDepNode(); // Get dependent node via edge with index i. //thisNode->edges(); //thisNode->getId(); //thisNode->getLabel(); // Add node markers XMarker thisNodeMarker(thisNodePos); std::string nodeName = "Node #" + mlPDF::intToString(nodeCount); thisNodeMarker.setName(nodeName.c_str()); thisNodeMarker.type = 0; _outNodePositions.appendItem(thisNodeMarker); // Add edge markers & connections const size_t thisNodeEdgesNum = thisNode->getEdgeNum(); // Get Number of edges dependent to the node. for (size_t e = 0; e < thisNodeEdgesNum; e++) { const VesselEdge* thisNodeEdge = thisNode->getDepEdge(e); // Get the pointer of edge with index i. if (thisNodeEdge) { bool newBranch = true; const size_t numSkeletons = thisNodeEdge->numSkeletons(); for (size_t s = 0; s < numSkeletons; s++) { const Skeleton* thisSkeleton = thisNodeEdge->skeleton(s); Vector3 thisSkeletonPos = thisSkeleton->getPos(); XMarker thisVesselEdgeMarker(thisSkeletonPos); thisVesselEdgeMarker.type = 0; // edgeCount; std::string edgeName = "Centerlines"; //std::string edgeName = "Edge #" + mlPDF::intToString(edgeCount); thisVesselEdgeMarker.setName(edgeName.c_str()); _outEdgePositions.appendItem(thisVesselEdgeMarker); /* if (s < numSkeletons - 1) { IndexPair thisVesselEdgeConnection((int)s, (int)s + 1); thisVesselEdgeConnection.type = edgeCount; _outEdgeConnections.appendItem(thisVesselEdgeConnection); } */ if (!newBranch) { IndexPair thisVesselEdgeConnection(currentEdgePositionNum - 1, currentEdgePositionNum); thisVesselEdgeConnection.type = 0; _outEdgeConnections.appendItem(thisVesselEdgeConnection); } currentEdgePositionNum++; newBranch = false; } edgeCount++; } } nodeCount++; } ML_DELETE(vesselGraph); _outNodePositionsFld->touch(); _outEdgePositionsFld->touch(); _outEdgeConnectionsFld->touch(); _createFibers(); }
ML_START_NAMESPACE //*********************************************************************************** void SavePRC::PreProcessMeshData(WEMPtr saveWEM, PRCMeshInfoVector &meshInfoVector, ModelBoundingBoxStruct& boundingBox) { if (!_inWEM) { return; } MLuint32 meshNumber = 0; bool simpleMode = _simpleModeMeshFld->getBoolValue(); StringVector meshSpecificationsVector; if (simpleMode) { //meshSpecificationsVector.push_back("<U3DMesh>"); } else { meshSpecificationsVector = getObjectSpecificationsStringFromUI(_meshSpecificationFld, "<Mesh>"); } // Scan all WEM patches, triangulate them if necessary and collect base info. WEMPatch* wemPatch = NULL; WEMTrianglePatch* addedTrianglePatch = NULL; _statusFld->setStringValue("Analyzing mesh specification and input WEM."); const MLuint32 numberOfWEMPatches = _inWEM->getNumWEMPatches(); for (MLuint32 i = 0; i < numberOfWEMPatches; i++) { PRCMeshInfoStruct thisWEMMeshInfo; wemPatch = _inWEM->getWEMPatchAt(i); addedTrianglePatch = NULL; const unsigned int newId = saveWEM->getCurrentWEMPatchId(); if (wemPatch->getNumFaces() > 0) { if (wemPatch->getPatchType() != WEM_PATCH_TRIANGLES) { WEMTrianglePatch* triangulatedPatch = NULL; ML_CHECK_NEW(triangulatedPatch,WEMTrianglePatch()); wemPatch->triangulate(triangulatedPatch, WEM_TRIANGULATION_STRIP); addedTrianglePatch = saveWEM->addWEMPatchCopy(triangulatedPatch); addedTrianglePatch->computeBoundingBox(); ML_DELETE(triangulatedPatch); } else { addedTrianglePatch = saveWEM->addWEMPatchCopy(reinterpret_cast<WEMTrianglePatch*>(wemPatch)); } if (addedTrianglePatch != NULL) { addedTrianglePatch->setId(newId); // Adjust properties of main WEM bounding box WEMBoundingBox* thisWEMPatchBoundingBox = addedTrianglePatch->getBoundingBox(); ModelBoundingBoxStruct newboundingBox; newboundingBox.start = thisWEMPatchBoundingBox->getMin(); newboundingBox.end = thisWEMPatchBoundingBox->getMax(); UpdateBoundingBox(boundingBox, newboundingBox); std::string wemDescription = addedTrianglePatch->getDescription(); std::string wemLabel = addedTrianglePatch->getLabel(); SpecificationParametersStruct thisSpecificationParameters; // Create an artificial meshSpecificationVector if only WEM label & description shall be used if (simpleMode) { meshSpecificationsVector.clear(); // Parse WEM label & description... std::string u3dModelName = getSpecificParameterFromWEMDescription(wemDescription, "ModelName"); std::string u3dGroupName = getSpecificParameterFromWEMDescription(wemDescription, "GroupName"); std::string u3dGroupPath = ""; if ("" != u3dModelName) { u3dGroupPath = "/" + u3dModelName + "/"; } if ("" != u3dGroupName) { if ("" == u3dGroupPath) { u3dGroupPath += "/"; } u3dGroupPath += u3dGroupName + "/"; } std::string displayName = wemLabel; if (displayName == "") { displayName = "Mesh " + intToString(i+1); } // ...and write data into meshSpecification string std::string meshSpecificationsString = "<U3DMesh>"; meshSpecificationsString += "<WEMLabel>" + wemLabel + "</WEMLabel>"; meshSpecificationsString += "<ObjectName>" + displayName + "</ObjectName>"; meshSpecificationsString += "<GroupPath>" + u3dGroupPath + "</GroupPath>"; meshSpecificationsString += "<Color>" + getSpecificParameterFromWEMDescription(wemDescription, "Color") + "</Color>"; meshSpecificationsString += "<SpecularColor>" + getSpecificParameterFromWEMDescription(wemDescription, "SpecularColor") + "</SpecularColor>"; meshSpecificationsString += "<ModelVisibility>3</ModelVisibility>"; // Add meshSpecification string to meshSpecificationVector meshSpecificationsVector.push_back(meshSpecificationsString); } for (int thisSpecificationIndex = 0; thisSpecificationIndex < meshSpecificationsVector.size(); thisSpecificationIndex++) { thisSpecificationParameters = getAllSpecificationParametersFromString(meshSpecificationsVector[thisSpecificationIndex]); if (thisSpecificationParameters.WEMLabel == wemLabel) { PRCObjectInfoStruct thisPRCObjectInfo = CreateNewPRCObjectInfo(i,PRCOBJECTTYPE_MESH, thisSpecificationParameters.ObjectName, defaultValues); thisPRCObjectInfo.GroupPath = thisSpecificationParameters.GroupPath; thisPRCObjectInfo.ParentTreeNodeID = -1; thisPRCObjectInfo.RGBAColor = getColorVec4(thisSpecificationParameters.Color, Vector4(0)); // If alpha = 0 -> Adobe doesn't render; _prcObjectInfoVector.push_back(thisPRCObjectInfo); // Collect mesh info thisWEMMeshInfo.DiffuseColorCount = 0; // This is not really needed in this version thisWEMMeshInfo.SpecularColorCount = 0; // This is not really needed in this version thisWEMMeshInfo.TextureCoordCount = 0; // This is not really needed in this version thisWEMMeshInfo.DefaultAmbientColor = defaultValues.defaultMaterialAmbientColor; thisWEMMeshInfo.DefaultSpecularColor = defaultValues.defaultMaterialSpecularColor; thisWEMMeshInfo.DefaultDiffuseColor = defaultValues.defaultMaterialDiffuseColorWithTransparency; thisWEMMeshInfo.DefaultEmissiveColor = defaultValues.defaultMaterialEmissiveColor; thisWEMMeshInfo.FaceCount = addedTrianglePatch->getNumFaces(); thisWEMMeshInfo.NormalCount = addedTrianglePatch->getNumFaces(); thisWEMMeshInfo.VertexCount = addedTrianglePatch->getNumNodes(); thisWEMMeshInfo.PatchID = addedTrianglePatch->getId(); // thisWEMMeshInfo.MeshAttributes = U3D_MESH_ATTRIBUTES_DEFAULT; // thisWEMMeshInfo.MeshAttributes |= ( (thisWEMMeshInfo.NormalCount == 0) ? U3D_MESH_ATTRIBUTES_EXCLUDENORMALS : 0 ); // thisWEMMeshInfo.ShadingAttributes = U3D_SHADINGATTRIBUTES_NONE; // thisWEMMeshInfo.ShadingAttributes |= ( (thisWEMMeshInfo.DiffuseColorCount > 0) ? U3D_SHADINGATTRIBUTES_DIFFUSECOLORS : 0 ); // Should not happen in this version // thisWEMMeshInfo.ShadingAttributes |= ( (thisWEMMeshInfo.SpecularColorCount > 0) ? U3D_SHADINGATTRIBUTES_SPECULARCOLORS : 0 ); // Should not happen in this version // thisWEMMeshInfo.ResourceName = thisPRCObjectInfo.ResourceName; thisWEMMeshInfo.MeshNumber = meshNumber++; meshInfoVector.push_back(thisWEMMeshInfo); } } } // if (addedTrianglePatch != NULL) } // if (wemPatch->getNumFaces() > 0) wemPatch = NULL; } }