vector<V3DLONG> landMarkList2poss(LandmarkList LandmarkList_input, V3DLONG _offset_Y, V3DLONG _offest_Z) { vector<V3DLONG> poss_result; V3DLONG count_landmark=LandmarkList_input.count(); for (V3DLONG idx_input=0;idx_input<count_landmark;idx_input++) { poss_result.push_back(landMark2pos(LandmarkList_input.at(idx_input), _offset_Y, _offest_Z)); } return poss_result; }
void processImage(V3DPluginCallback2 &callback, QWidget *parent) { v3dhandle curwin = callback.currentImageWindow(); if (!curwin) { v3d_msg("You don't have any image open in the main window."); return; } Image4DSimple* p4DImage = callback.getImage(curwin); QString imgname = callback.getImageName(curwin); if (!p4DImage) { v3d_msg("The image pointer is invalid. Ensure your data is valid and try again!"); return; } int tmpx,tmpy,tmpz,x1,y1,z1; LandmarkList listLandmarks = callback.getLandmark(curwin); LocationSimple tmpLocation(0,0,0); int marknum = listLandmarks.count(); if(marknum ==0) { v3d_msg("No markers in the current image, please double check."); return; } UndirectedGraph g(marknum); for (int i=0;i<marknum;i++) { tmpLocation = listLandmarks.at(i); tmpLocation.getCoord(tmpx,tmpy,tmpz); x1 = tmpx; y1 = tmpy; z1 = tmpz; for (int j=0;j<marknum;j++) { EdgeQuery edgeq = edge(i, j, *&g); if (!edgeq.second && i!=j) { tmpLocation = listLandmarks.at(j); tmpLocation.getCoord(tmpx,tmpy,tmpz); double Vedge = sqrt(double(x1-tmpx)*double(x1-tmpx) + double(y1-tmpy)*double(y1-tmpy) + double(z1-tmpz)*double(z1-tmpz)); add_edge(i, j, LastVoted(i, Weight(Vedge)), *&g); } } } // property_map<UndirectedGraph, edge_weight_t>::type weightmap = get(edge_weight, *&g); vector < graph_traits < UndirectedGraph >::vertex_descriptor > p(num_vertices(*&g)); prim_minimum_spanning_tree(*&g, &p[0]); NeuronTree marker_MST; QList <NeuronSWC> listNeuron; QHash <int, int> hashNeuron; listNeuron.clear(); hashNeuron.clear(); for (std::size_t i = 0; i != p.size(); ++i) { NeuronSWC S; tmpLocation = listLandmarks.at(i); tmpLocation.getCoord(tmpx,tmpy,tmpz); int pn; if(p[i] == i) pn = -1; else pn = p[i] + 1; S.n = i+1; S.type = 7; S.x = tmpx; S.y = tmpy; S.z = tmpz; S.r = 1; S.pn = pn; listNeuron.append(S); hashNeuron.insert(S.n, listNeuron.size()-1); } marker_MST.n = -1; marker_MST.on = true; marker_MST.listNeuron = listNeuron; marker_MST.hashNeuron = hashNeuron; /* double** markEdge = new double*[marknum]; for(int i = 0; i < marknum; i++) { markEdge[i] = new double[marknum]; } for (int i=0;i<marknum;i++) { tmpLocation = listLandmarks.at(i); tmpLocation.getCoord(tmpx,tmpy,tmpz); x1 = tmpx; y1 = tmpy; z1 = tmpz; for (int j=0;j<marknum;j++) { tmpLocation = listLandmarks.at(j); tmpLocation.getCoord(tmpx,tmpy,tmpz); markEdge[i][j] = sqrt(double(x1-tmpx)*double(x1-tmpx) + double(y1-tmpy)*double(y1-tmpy) + double(z1-tmpz)*double(z1-tmpz)); } } //NeutronTree structure NeuronTree marker_MST; QList <NeuronSWC> listNeuron; QHash <int, int> hashNeuron; listNeuron.clear(); hashNeuron.clear(); //set node NeuronSWC S; tmpLocation = listLandmarks.at(0); tmpLocation.getCoord(tmpx,tmpy,tmpz); S.n = 1; S.type = 7; S.x = tmpx; S.y = tmpy; S.z = tmpz; S.r = 1; S.pn = -1; listNeuron.append(S); hashNeuron.insert(S.n, listNeuron.size()-1); int* pi = new int[marknum]; for(int i = 0; i< marknum;i++) pi[i] = 0; pi[0] = 1; int indexi,indexj; for(int loop = 0; loop<marknum;loop++) { double min = INF; for(int i = 0; i<marknum; i++) { if (pi[i] == 1) { for(int j = 0;j<marknum; j++) { if(pi[j] == 0 && min > markEdge[i][j]) { min = markEdge[i][j]; indexi = i; indexj = j; } } } } if(indexi>=0) { tmpLocation = listLandmarks.at(indexj); tmpLocation.getCoord(tmpx,tmpy,tmpz); S.n = indexj+1; S.type = 7; S.x = tmpx; S.y = tmpy; S.z = tmpz; S.r = 1; S.pn = indexi+1; listNeuron.append(S); hashNeuron.insert(S.n, listNeuron.size()-1); }else { break; } pi[indexj] = 1; indexi = -1; indexj = -1; } marker_MST.n = -1; marker_MST.on = true; marker_MST.listNeuron = listNeuron; marker_MST.hashNeuron = hashNeuron; */ QString outfilename = imgname + "_boost_marker.swc"; if (outfilename.startsWith("http", Qt::CaseInsensitive)) { QFileInfo ii(outfilename); outfilename = QDir::home().absolutePath() + "/" + ii.fileName(); } //v3d_msg(QString("The anticipated output file is [%1]").arg(outfilename)); writeSWC_file(outfilename,marker_MST); v3d_msg(QString("You have totally [%1] markers for the file [%2] and the computed MST has been saved to the file [%3]").arg(marknum).arg(imgname).arg(outfilename)); return; }