void LoadPointLineGeometry::_updateOutputData() { _outPositionsList.clearList(); _outConnectionsList.clearList(); std::string newSetFilter = ""; std::string newSetName = ""; int newSetType = 0; std::string filterString = _filterFld->getStringValue(); std::string numberDelimiter = _numberDelimiterFld->getStringValue(); if (_numberDelimiterSpaceFld->getBoolValue()) { numberDelimiter = " "; } std::string decimalSeparator = _decimalSeparatorFld->getStringValue(); for(StringVector::iterator it = _inputFileLinesVector.begin(); it != _inputFileLinesVector.end(); ++it) { std::string thisLine = *it; StringVector thisDataLineComponents = mlPDF::PDFTools::stringSplit(thisLine, " ", false); size_t thisDataLineNumComponents = thisDataLineComponents.size(); if (thisDataLineNumComponents > 0) { // Check if new set definition is started if (thisDataLineNumComponents > 1) // Must be at least a a <Tag> <Type> {<Name>} pair/triple { std::string firstComponent = thisDataLineComponents[0]; if (isalpha(firstComponent[0])) { newSetFilter = firstComponent; newSetType = mlPDF::stringToInt(thisDataLineComponents[1]); if (thisDataLineNumComponents > 2) { newSetName = ""; // Append all remaining fragments to the name for (size_t i = 2; i < thisDataLineNumComponents; i++) { if (newSetName != "") { newSetName += " "; } newSetName += thisDataLineComponents[i]; } } else { newSetName = ""; } continue; } } if ((filterString == "") || (filterString == newSetFilter)) { // If it is a list of connections if (thisDataLineNumComponents == 2) { // Add point (only the first 3 components) int start = mlPDF::stringToInt(thisDataLineComponents[0]); int end = mlPDF::stringToInt(thisDataLineComponents[1]); IndexPair newConnection(start, end, newSetType, newSetName.c_str()); _outConnectionsList.appendItem(newConnection); } // If it is a list of positions else if (thisDataLineNumComponents > 2) { // Add point (only the first 3 components) double x = mlPDF::stringToDouble(thisDataLineComponents[0]); double y = mlPDF::stringToDouble(thisDataLineComponents[1]); double z = mlPDF::stringToDouble(thisDataLineComponents[2]); XMarker newPosition(Vector6(x, y, z, 0, 0, 0), newSetType, newSetName.c_str()); _outPositionsList.appendItem(newPosition); } } } // if (thisDataLineNumComponents > 0) } // for(StringVector::iterator it // Deselect items _outPositionsList.selectItemAt(-1); _outConnectionsList.selectItemAt(-1); _createFibers(); if (_autoAddToCacheFld->getBoolValue()) { _addToCache(); } // Set validation fields _positionsLoadedFld->setBoolValue(_outPositionsList.size() > 0); _connectionsLoadedFld->setBoolValue(_outConnectionsList.size() > 0); // Update output _outPositionsListFld->touch(); _outConnectionsListFld->touch(); _outFibersFld->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(); }