InputMatrix::InputMatrix(std::istream& input) { START_COLLECT_TIME(readingInput, Counters::ReadingInput); input >> _rowsCount; input >> _qColsCount; _qMatrix = new int[_rowsCount * _qColsCount]; _qMinimum = new int[_qColsCount]; _qMaximum = new int[_qColsCount]; for(auto j=0; j<_qColsCount; ++j) { _qMinimum[j] = DASH; _qMaximum[j] = DASH; } for(auto i=0; i<_rowsCount; ++i) { for(auto j=0; j<_qColsCount; ++j) { auto value = parseValue(input); setFeature(i, j, value); if (value != DASH) { if (_qMinimum[j] == DASH || value < _qMinimum[j]) _qMinimum[j] = value; if (_qMaximum[j] == DASH || _qMaximum[j] < value) _qMaximum[j] = value; } } } input >> _rColsCount; _rMatrix = new int[_rowsCount * _rColsCount]; for(auto i=0; i<_rowsCount; ++i) { for(auto j=0; j<_rColsCount; ++j) { setImage(i, j, parseValue(input)); } } _r2Matrix = new int[_rowsCount]; STOP_COLLECT_TIME(readingInput); START_COLLECT_TIME(preparingInput, Counters::PreparingInput); calcR2Matrix(); sortMatrix(); calcR2Indexes(); STOP_COLLECT_TIME(preparingInput); }
void BranchList::findBranchesInCenterline(Eigen::MatrixXd positions) { positions = sortMatrix(2,positions); Eigen::MatrixXd positionsNotUsed = positions; // int minIndex; int index; int splitIndex; Eigen::MatrixXd::Index startIndex; BranchPtr branchToSplit; while (positionsNotUsed.cols() > 0) { if (!mBranches.empty()) { double minDistance = 1000; for (int i = 0; i < mBranches.size(); i++) { std::pair<std::vector<Eigen::MatrixXd::Index>, Eigen::VectorXd> distances; distances = dsearchn(positionsNotUsed, mBranches[i]->getPositions()); double d = distances.second.minCoeff(&index); if (d < minDistance) { minDistance = d; branchToSplit = mBranches[i]; startIndex = index; if (minDistance < 2) break; } } std::pair<Eigen::MatrixXd::Index, double> dsearchResult = dsearch(positionsNotUsed.col(startIndex) , branchToSplit->getPositions()); splitIndex = dsearchResult.first; } else //if this is the first branch. Select the top position (Trachea). startIndex = positionsNotUsed.cols() - 1; std::pair<Eigen::MatrixXd,Eigen::MatrixXd > connectedPointsResult = findConnectedPointsInCT(startIndex , positionsNotUsed); Eigen::MatrixXd branchPositions = connectedPointsResult.first; positionsNotUsed = connectedPointsResult.second; if (branchPositions.cols() >= 5) //only include brances of length >= 5 points { BranchPtr newBranch = BranchPtr(new Branch()); newBranch->setPositions(branchPositions); mBranches.push_back(newBranch); if (mBranches.size() > 1) // do not try to split another branch when the first branch is processed { if ((splitIndex + 1 >= 5) && (branchToSplit->getPositions().cols() - splitIndex - 1 >= 5)) //do not split branch if the new branch is close to the edge of the branch //if the new branch is not close to one of the edges of the //connected existing branch: Split the existing branch { BranchPtr newBranchFromSplit = BranchPtr(new Branch()); Eigen::MatrixXd branchToSplitPositions = branchToSplit->getPositions(); newBranchFromSplit->setPositions(branchToSplitPositions.rightCols(branchToSplitPositions.cols() - splitIndex - 1)); branchToSplit->setPositions(branchToSplitPositions.leftCols(splitIndex + 1)); mBranches.push_back(newBranchFromSplit); newBranchFromSplit->setParentBranch(branchToSplit); newBranch->setParentBranch(branchToSplit); newBranchFromSplit->setChildBranches(branchToSplit->getChildBranches()); branchVector branchToSplitChildren = branchToSplit->getChildBranches(); for (int i = 0; i < branchToSplitChildren.size(); i++) branchToSplitChildren[i]->setParentBranch(newBranchFromSplit); branchToSplit->deleteChildBranches(); branchToSplit->addChildBranch(newBranchFromSplit); branchToSplit->addChildBranch(newBranch); } else if (splitIndex + 1 < 5) // If the new branch is close to the start of the existing // branch: Connect it to the same position start as the // existing branch { newBranch->setParentBranch(branchToSplit->getParentBranch()); branchToSplit->getParentBranch()->addChildBranch(newBranch); } else if (branchToSplit->getPositions().cols() - splitIndex - 1 < 5) // If the new branch is close to the end of the existing // branch: Connect it to the end of the existing branch { newBranch->setParentBranch(branchToSplit); branchToSplit->addChildBranch(newBranch); } } } } }