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; }
TargetList::TargetList(QWidget *parent) : QWidget(parent) { targetTable = new QTableWidget(1,3,this); scanLocTable = new QTableWidget(1,5,this); QLabel* targetTableLabel = new QLabel("&Targets"); QLabel* scanLocTableLabel = new QLabel("ROI locations"); QStringList ttHeaders; ttHeaders.append("Target Number"); ttHeaders.append("x (um)"); ttHeaders.append("y (um)"); targetTable->setHorizontalHeaderLabels(ttHeaders); QStringList sltHeaders; sltHeaders.append("ROI Number"); sltHeaders.append("x (um)"); sltHeaders.append("y (um)"); sltHeaders.append("x width"); sltHeaders.append("y width"); scanLocTable->setHorizontalHeaderLabels(sltHeaders); targetTableLabel->setBuddy(targetTable); connect(targetTable,SIGNAL(cellClicked(int,int)), this, SLOT(updateScanTable(int,int))); mainLayout = new QGridLayout; mainLayout->addWidget(targetTableLabel,0,0); mainLayout->addWidget(targetTable, 1,0,3,1); mainLayout->addWidget(scanLocTableLabel,0,1); mainLayout->addWidget(scanLocTable,1,2,3,2 ); scanLocTable->adjustSize(); targetTable->adjustSize(); setLayout(mainLayout); qDebug()<<"constructed targettable"; qDebug()<<QString::number(scanLocTable->isVisible()); LandmarkList fakeTargetList; LocationSimple testLoc1; fakeTargetList.append(testLoc1); QList<LandmarkList> fakeScanLocations; fakeScanLocations.append(fakeTargetList); updateTargetTable(fakeTargetList, fakeScanLocations); }
void TargetList::updateTargetTable(LandmarkList inputTargetList, QList<LandmarkList> inputScanLocations){ qDebug()<<"updating Table"; targetList = inputTargetList; scanLocations = inputScanLocations; if (inputTargetList.isEmpty()){ qDebug()<<"no targets"; return; } targetTable->clearContents(); for (int i=0; i<inputTargetList.length(); i++){ targetTable->insertRow(i); QTableWidgetItem *cell = targetTable->item(i,0); if (!cell){ cell = new QTableWidgetItem; targetTable->setItem(i,0,cell); } cell->setText(QString::number(i)); cell = targetTable->item(i,1); if (!cell){ cell = new QTableWidgetItem; targetTable->setItem(i,1,cell); } cell->setText(QString::number(inputTargetList.value(i).x)); cell = targetTable->item(i,2); if (!cell){ cell = new QTableWidgetItem; targetTable->setItem(i,2,cell); } cell->setText(QString::number(inputTargetList.value(i).y)); } targetTable->setCurrentCell(0,0); targetTable->adjustSize(); }
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; }
void reconstruction_func(V3DPluginCallback2 &callback, QWidget *parent, input_PARA &PARA, bool bmenu) { unsigned char* data1d = 0; V3DLONG N,M,P,sc,c; V3DLONG in_sz[4]; v3dhandle curwin; if(bmenu) { curwin = callback.currentImageWindow(); v3dhandle curwin = callback.currentImageWindow(); if (!curwin) { QMessageBox::information(0, "", "You don't have any image open in the main window."); return; } Image4DSimple* p4DImage = callback.getImage(curwin); if (!p4DImage) { QMessageBox::information(0, "", "The image pointer is invalid. Ensure your data is valid and try again!"); return; } data1d = p4DImage->getRawData(); N = p4DImage->getXDim(); M = p4DImage->getYDim(); P = p4DImage->getZDim(); sc = p4DImage->getCDim(); in_sz[0] = N; in_sz[1] = M; in_sz[2] = P; in_sz[3] = sc; PARA.inimg_file = p4DImage->getFileName(); } else { int datatype = 0; if (!simple_loadimage_wrapper(callback,PARA.inimg_file.toStdString().c_str(), data1d, in_sz, datatype)) { fprintf (stderr, "Error happens in reading the subject file [%s]. Exit. \n",PARA.inimg_file.toStdString().c_str()); return; } N = in_sz[0]; M = in_sz[1]; P = in_sz[2]; sc = in_sz[3]; } //main neuron reconstruction code //// THIS IS WHERE THE DEVELOPERS SHOULD ADD THEIR OWN NEURON TRACING CODE // ofstream oImgInfofile; string sImgPath = PARA.inimg_file.toStdString(); g_sAppDir = normalizePath(parentPath(sImgPath)); // g_sImageInfoPath = g_sAppDir + g_sImageInfoName; // g_sInputRawFilePath = g_sAppDir + g_sInputRawFileName; QString swc_name = PARA.inimg_file + "_nctuTW.swc"; g_sOutSwcFilePath = swc_name.toStdString(); //g_sOutSwcFilePath = g_sAppDir+ g_sOutSwcFileName; size_t nDataSize = N * M * P * sc ; width = N; height = M; zSize = P; // oImgInfofile.open(g_sImageInfoPath.data(), ios::out|ios::binary); // if(oImgInfofile.is_open()){ // oImgInfofile << N << " " << M << " " << P << endl; // oImgInfofile.close(); // } imgBuf_raw = new unsigned char [nDataSize]; memcpy(imgBuf_raw, data1d, nDataSize); // ofstream oRawFile; // oRawFile.open(g_sInputRawFilePath.data(), ios::out|ios::binary); // if(oRawFile.is_open()){ // oRawFile.write((char *)data1d, nDataSize); // oRawFile.close(); // } /* // For debug if(nParaState == QDialog::Accepted){ std::string sPara = "Threshold = " + toString(g_rThreshold) + "; " + "Soma = (" + toString(g_nSomaX) + ", " + toString(g_nSomaY) + ", " + toString(g_nSomaZ) + ")"; v3d_msg(QString(sPara.c_str())); } */ QDlgPara* pqDlgPara; g_nSomaX = -1; g_nSomaY = -1; g_nSomaZ = -1; int nParaState = 1; if(bmenu) //ui { LandmarkList Landmark; Landmark = callback.getLandmark(curwin); if(Landmark.size()>0) { g_nSomaX = Landmark.at(0).x-1; g_nSomaY = Landmark.at(0).y-1; g_nSomaZ = Landmark.at(0).z-1; } pqDlgPara = new QDlgPara(parent); nParaState = pqDlgPara->exec(); } else //command line { QList<ImageMarker> file_inmarkers; if(!PARA.inmarker_file.isEmpty()) { file_inmarkers = readMarker_file(PARA.inmarker_file); g_nSomaX = file_inmarkers.at(0).x; g_nSomaY = file_inmarkers.at(0).y; g_nSomaZ = file_inmarkers.at(0).z; } else { g_nSomaX = -1; g_nSomaY = -1; g_nSomaZ = -1; } g_rThreshold = PARA.threshold; } if(nParaState) { NeuronTracingMain(); v3d_msg(QString("Now you can drag and drop the generated swc fle [%1] into Vaa3D.").arg(swc_name.toStdString().c_str()),bmenu); } if(bmenu) delete pqDlgPara; bmenu=true; //Output // NeuronTree nt; //QString swc_name = PARA.inimg_file + "_nctuTW.swc"; // nt.name = "nctuTW"; // writeSWC_file(swc_name.toStdString().c_str(),nt); //QString swc_name(g_sOutSwcFilePath.data()); //Output if(!bmenu) { if(data1d) {delete []data1d; data1d = 0;} } delete [] imgBuf_raw; return; }
bool load_data(V3DPluginCallback2 *cb,unsigned char * & image1Dc_in,LandmarkList &LList,ImagePixelType &pixeltype, V3DLONG sz_img[4],v3dhandle &curwin) { V3DPluginCallback2 *callback=cb; v3dhandleList v3dhandleList_current=callback->getImageWindowList(); QList <V3dR_MainWindow *> cur_list_3dviewer = callback->getListAll3DViewers(); LandmarkList LList_in; if (v3dhandleList_current.size()==0){ v3d_msg("Please open image and select markers"); return false; } else if (v3dhandleList_current.size()==1) //One window open { //get markers and check markers LList_in.clear(); LList_in = callback->getLandmark(v3dhandleList_current[0]); if (LList_in.size()==0) { v3d_msg("Please load markers"); return false; } curwin=v3dhandleList_current[0]; } else if (v3dhandleList_current.size()>1) { QStringList items; int i; for (i=0; i<v3dhandleList_current.size(); i++) items << callback->getImageName(v3dhandleList_current[i]); for (i=0; i<cur_list_3dviewer.count(); i++) { QString curname = callback->getImageName(cur_list_3dviewer[i]).remove("3D View [").remove("]"); bool b_found=false; for (int j=0; j<v3dhandleList_current.size(); j++) if (curname==callback->getImageName(v3dhandleList_current[j])) { b_found=true; break; } if (!b_found) items << callback->getImageName(cur_list_3dviewer[i]); } //qDebug()<<"Number of items:"<<items.size(); QDialog *mydialog=new QDialog; QComboBox *combo=new QComboBox; combo->insertItems(0,items); QLabel *label_win=new QLabel; label_win->setText("You have multiple windows open, please select one image:"); QGridLayout *layout= new QGridLayout; layout->addWidget(label_win,0,0,1,1); layout->addWidget(combo,1,0,4,1); QPushButton *button_d_ok=new QPushButton("Ok"); button_d_ok->setFixedWidth(100); QPushButton *button_d_cancel=new QPushButton("Cancel"); button_d_cancel->setFixedWidth(100); QHBoxLayout *box=new QHBoxLayout; box->addWidget(button_d_ok,Qt::AlignCenter); box->addWidget(button_d_cancel,Qt::AlignCenter); layout->addLayout(box,5,0,1,1); QDialog::connect(button_d_ok,SIGNAL(clicked()),mydialog,SLOT(accept())); QDialog::connect(button_d_cancel,SIGNAL(clicked()),mydialog,SLOT(reject())); mydialog->setLayout(layout); mydialog->exec(); if (mydialog->result()==QDialog::Accepted) { int tmp=combo->currentIndex(); curwin=v3dhandleList_current[tmp]; } else { v3d_msg("You have not selected a window"); return false; } //get markers and check markers LList_in.clear(); LList_in = callback->getLandmark(curwin); if (LList_in.size()==0) { v3d_msg("Please load markers"); return false; } } //Get the image info Image4DSimple* p4DImage = callback->getImage(curwin); if (!p4DImage){ QMessageBox::information(0, "", "The image pointer is invalid. Ensure your data is valid and try again!"); return false; } sz_img[0]=p4DImage->getXDim(); sz_img[1]=p4DImage->getYDim(); sz_img[2]=p4DImage->getZDim(); sz_img[3]=p4DImage->getCDim(); if (sz_img[3]>3){ sz_img[3]=3; QMessageBox::information(0,"","More than 3 channels were loaded." "The first 3 channel will be applied for analysis."); } V3DLONG size_tmp=sz_img[0]*sz_img[1]*sz_img[2]*sz_img[3]; pixeltype = p4DImage->getDatatype(); image1Dc_in=memory_allocate_uchar1D(size_tmp); unsigned char * ptmp=p4DImage->getRawData(); memcpy(image1Dc_in,ptmp,size_tmp*pixeltype); LList.clear(); for(int i=0; i<LList_in.size(); i++){ LList.append(LList_in.at(i)); LList[i].color.r=196; LList[i].color.g=LList[i].color.b=0; } return true; }
//return a list of predictions ? Or a mask image? // Also need numbers of cells, and centers of cells //work on local maxima //use different preprocessing, feature extraction etc. //1d_dimension is ROIDImension + 1 //Note: be aware of the order x, y, z are passed to submethods. unsigned char* CellClassifier::annotateAnImage(V3DPluginCallback &callback, v3dhandle win, Image4DSimple* image, int ch, int grid, int dimension_1d) { std::vector <LocationSimple> detectedPos; LandmarkList markerList; long sx=image->sz0, sy=image->sz1, sz=image->sz2; long pagesz=sx*sy; long channelsz=sx*sy*sz; //smoothed and get local maxima //sensitive gaussian filtering radius // ??????? use distance transform image??????? int Wx = dimension_1d, Wy = dimension_1d, Wz = dimension_1d; unsigned char * filtered = gaussianfiltering(image->getRawData(), sx, sy, sz, Wx, Wy, Wz); unsigned char * flag_lm = check_localMaxima_ker(filtered, sx, sy, sz, 0); //unsigned char * flag_lm = check_localMaxima(callback, image, ch); //062110 unsigned char *results = new unsigned char [channelsz]; //prediction results. if (!results) { printf("Fail to allocate memory.\n"); return NULL; } unsigned char *clearFlag = new unsigned char [channelsz]; //prediction results. if (!clearFlag) { printf("Fail to allocate memory.\n"); return NULL; } //get model from file //string modelfile = "test_svm_model.txt"; struct svm_model * pmodel = pclassifier->loadSVMModel(); int r = dimension_1d/2; int prediction; int total = 0, cellcount = 0; //use (a somehow more restrict) template matching for adding some candidates. bool candidateflag = false; long cubesize = dimension_1d*dimension_1d*dimension_1d; double sigmax = (dimension_1d-1)/4.0, sigmay = (dimension_1d-1)/4.0, sigmaz = (dimension_1d-1)/4.0; double *g_1d = genGaussianKernel1D(dimension_1d, dimension_1d, dimension_1d, sigmax, sigmay, sigmaz); double curcoeff; //double coeff_th = 0.66; //will use average coeff of positive ones from training!!!! //init results for(long iz = 0; iz < sz; iz++) { long offsetk = iz*sx*sy; for(long iy = 0; iy < sy; iy++) { long offsetj = iy*sx; for(long ix = 0; ix < sx; ix++) { long idx = offsetk + offsetj + ix; results[idx] = 0; clearFlag[idx] = 1; //will be cleared later } } } //start search int denied = 0; for(long iz = r; iz < sz-r; iz++) { long offsetk = iz*sx*sy; for(long iy = r; iy < sy-r; iy++) { long offsetj = iy*sx; for(long ix = r; ix < sx-r; ix++) { long idx = offsetk + offsetj + ix; //debug: //if(ix == 61 && iy==39 && iz==17) cout << "the missed one is here!!" << (int) flag_lm[idx] << endl; //if(ix == 63 && iy ==43 && iz ==16) cout << "the valley one (#3) is here!!" << (int) flag_lm[idx] << endl;; //if(ix == 65 && iy ==43 && iz ==14) cout << "the valley start point is here!!" << (int) flag_lm[idx] << endl;; if(flag_lm[idx] == 255 && clearFlag[idx] == 1 ) //only work on local maxima (and not cleared) { //classify to see if it is a center prediction = classifyAVoxel(image, ch, iz, iy, ix, dimension_1d, pmodel); if(prediction == 0) denied ++; candidateflag = false; if (prediction == 1 || candidateflag) { //cellcount ++; //results[idx] = 255; // double ncx, ncy, ncz; unsigned char * currentCube =getACube(image, ch, iz, iy, ix, dimension_1d, dimension_1d*dimension_1d, pagesz, channelsz); //fixed a bug 060210 curcoeff = coeff(currentCube, g_1d, cubesize); //debug if(ix == 65 && iy ==43 && iz ==14) std::cout << "coeff at valley:" << curcoeff << std::endl ; delete[] currentCube; //if(curcoeff < 0.45) //{ // std::cout << "coeff too low for (" << ix << " " << iy << " " << iz << ") " << " coef: " << curcoeff << endl; // continue; //} //converge toward center of mass, //move the center using highest score (either matching or classifier). /* getMatchingCenter(image, ix, iy, iz, r, ch, ncx, ncy, ncz, flag_lm); double nncx, nncy, nncz; //getMassCenter(image, ncx, ncy, ncz, r, ch, nncx, nncy, nncz, flag_lm); getMassCenter(filtered, sx,sy,sz, ncx, ncy, ncz, r, ch, nncx, nncy, nncz, flag_lm); int newx = (int) (nncx+0.5), newy = (int) (nncy+0.5), newz = (int) (nncz+0.5); //rounding */ getMassCenter(filtered, sx,sy,sz, ix, iy, iz, r, ch, ncx, ncy, ncz, flag_lm); int newx = (int) (ncx+0.5), newy = (int) (ncy+0.5), newz = (int) (ncz+0.5); //rounding //make a final decision if, after moving, there is a close neighbor identified already on the new spot if (nearACenter(newx, newy, newz, results, r, sx, sy, sz)) { // std::cout << "#" << cellcount << ", there's 1 nearby. Skip. " ; continue; } long foundidx = newz*sx*sy + newy*sx + newx; //check if move to a lm , possible for valley area between cells. //why this made the debug image has 20 down to 9 cells!! /*if ( flag_lm[foundidx] == 0) { std::cout << "non-lm. Skip. " ; continue; }*/ //else: a cell is found, set that to 255 results[foundidx] = 255; //remove foreground around that center from image: based on radius? reestimate based on std? //int testt=0; for(int lll =0; lll < channelsz; lll++) if (flag_lm[lll] ==255) testt ++; //cout << "postive flags: " << testt << endl; //will not consider its neighbors in the future. clearSurrounding(image, ch, newx, newy, newz, r, clearFlag); //testt=0; for(int lll =0; lll < channelsz; lll++) if (flag_lm[lll] ==255) testt ++; //cout << "postive flags after: " << testt << endl; //increase cell counter by 1. LocationSimple pp(newx, newy, newz); detectedPos.push_back(pp); LocationSimple marker(newx +1, newy +1, newz +1); //convert back to 1-base marker.radius = r; markerList.push_back(marker); cellcount ++; } }//end local maxima }//end ix }//end iy }//end iz std::cout << "total number of cells:" << cellcount << std::endl; char buf[30]; itoa(cellcount, buf, 10); string resstring = "total cells:"; resstring.append(buf); QMessageBox::information(0, "debug", QString(resstring.c_str())); std::cout << "total denied local maximum:" << denied << std::endl; svm_destroy_model(pmodel); /* //results only Image4DSimple p4DImage; p4DImage.setData(results, sx, sy, sz, 1, image->datatype); v3dhandle newwin = callback.newImageWindow(); callback.setImage(newwin, &p4DImage); callback.setImageName(newwin, "prediction results image"); callback.updateImageWindow(newwin); */ //v3d does not allow me to use the same image data in a different (new) window? //I need to make a copy of the data first? unsigned char *newimage1d = new unsigned char [channelsz]; if(!newimage1d) { std::cout << "not enough memory to create result window"; return results; } unsigned char* image1d = image->getRawData(); for(long n = 0; n < channelsz; n++) newimage1d[n] = image1d[ch*channelsz + n]; //show resulting cell markers in a new window Image4DSimple newImage; newImage.setData(newimage1d, sx, sy, sz, 1, image->datatype); v3dhandle newwin = callback.newImageWindow(); callback.setImage(newwin, &newImage); callback.setImageName(newwin, "cell_counted"); callback.updateImageWindow(newwin); callback.setLandmark(newwin, markerList); //de-alloc //should I close svm file here??? if(filtered) { std::cout << "clean up memory for filtered image." << endl; delete[] filtered; } if(flag_lm) { std::cout << "clean up memory for local maximum." << endl; delete[] flag_lm; } if(clearFlag) { std::cout << "clean up memory for flags." << endl; delete[] clearFlag; } return results; }
//void startVesselTracing ( V3DPluginCallback2 &v3d, QWidget *parent ) void startVesselTracing(V3DPluginCallback2 &v3d,int xflag,int yflag,int zflag,int xbegin, int xend,int xdis,int ybegin,int yend,int ydis,int zbegin,int zend,int zdis,QString swcfile,int slipsize,int pruning_flag,int c) { v3dhandle curwin = v3d.currentImageWindow(); if (!curwin) { v3d_msg("You don't have any image open in the main window."); return; } //ensure the 3d viewer window is open; if not, then open it // v3d.open3DWindow(curwin); // get land mark list LandmarkList seedList = v3d.getLandmark(curwin); Image4DSimple* oldimg = v3d.getImage(curwin); unsigned char* data1d = oldimg->getRawDataAtChannel(c-1); ImagePixelType pixeltype = oldimg->getDatatype(); V3DLONG pagesz = oldimg->getTotalUnitNumberPerChannel(); unsigned char *output_image=0; switch (pixeltype) { case V3D_UINT8: try {output_image = new unsigned char [pagesz];} catch(...) {v3d_msg("cannot allocate memory for output_image."); return;} for(V3DLONG i = 0; i<pagesz; i++) output_image[i] = data1d[i]; break; default: v3d_msg("Invalid data type. Do nothing."); return; } V3DLONG in_sz[4]; in_sz[0] = oldimg->getXDim(); in_sz[1] = oldimg->getYDim(); in_sz[2] = oldimg->getZDim();in_sz[3] = 1; // simple_saveimage_wrapper(v3d, "temp.v3draw", (unsigned char *)output_image, in_sz, pixeltype); MOSTImage img; // set data img.setData( (unsigned char*)output_image, oldimg->getXDim(),oldimg->getYDim(),oldimg->getZDim(),oldimg->getCDim(),oldimg->getDatatype()); if ( seedList.isEmpty() ) { QTime qtime_seed; qtime_seed.start(); //img.auto_detect_seedz(seedList,img.getZDim()/2); if(xflag) { for(int i =xbegin;i<=xend;i+=xdis) img.auto_detect_seedx(seedList,i,InitThreshold,seed_size_all); // img.auto_detect_seedx(seedList,xend); } if(yflag) { for(int i =ybegin;i<=yend;i+=ydis) img.auto_detect_seedy(seedList,i,InitThreshold,seed_size_all); // img.auto_detect_seedy(seedList,yend); } if(zflag) { for(int i =zbegin;i<=zend;i+=zdis) img.auto_detect_seedz(seedList,i,InitThreshold,seed_size_all); //img.auto_detect_seedz(seedList,zend); } qDebug(" cost time seed = %g sec", qtime_seed.elapsed()*0.001); } // clear visited, only excute once static long init_flag = 0; /* if ( init_flag <= 0 ) { visited.fill( false, oldimg->getTotalUnitNumber()); init_flag ++; }*/ for(init_flag = 0;init_flag<oldimg->getTotalUnitNumber();init_flag++) { visited.push_back(false); } // converte the formate NeuronTree vt; QTime qtime; qtime.start(); vt = img.trace_seed_list(seedList, visited,InitThreshold,res_x_all,res_y_all,res_z_all,swcfile,slipsize,pruning_flag); qDebug(" cost time totol= %g sec", qtime.elapsed()*0.001); v3d_msg(QString("Now you can drag and drop the generated swc fle [%1] into Vaa3D.").arg(swcfile),1); // NeuronTree vt_old = v3d.getSWC(curwin); // visualization // v3d.setLandmark(curwin, seedList); // v3d.setSWC(curwin,vt); // v3d.pushObjectIn3DWindow(curwin); // v3d.updateImageWindow(curwin); //img.~MOSTImage(); }
int v3dneuron_tracing(V3DPluginCallback2 &callback, QWidget *parent) { v3dhandleList win_list = callback.getImageWindowList(); if(win_list.size()<1) { QMessageBox::information(0, title, QObject::tr("No image is open.")); return -1; } v3dhandle curwin = callback.currentImageWindow(); LandmarkList landmarks = callback.getLandmark(curwin); if(landmarks.empty()) { v3d_msg("Please set a landmark!"); return 0; } QList <ImageMarker> imagemarks; for(int i = 0; i < landmarks.size(); i++) { ImageMarker m; LocationSimple l = landmarks.at(i); m.x = l.x; m.y = l.y; m.z = l.z; imagemarks.push_back(m); } system("rm -f /tmp/mymarks.marker"); system("rm -f /tmp/tmp_out*"); writeMarker_file("/tmp/mymarks.marker",imagemarks); QString img_file = callback.getImageName(curwin); bool ok; QString nt_path = QInputDialog::getText(0, QObject::tr("Set path"), QObject::tr("v3dneuron_tracing path : "), QLineEdit::Normal, "~/Local/bin/v3dneuron_tracing", &ok); //QString paras = QObject::tr("v3dneuron_tracing -s %1 -S /tmp/mymarks.marker -o /tmp/tmp_out").arg(img_file); QString paras = QObject::tr("%1 -s \"%2\" -S /tmp/mymarks.marker -o /tmp/tmp_out").arg(nt_path).arg(img_file); qDebug(paras.toStdString().c_str()); //QMessageBox::information(0,"",paras); system(paras.toStdString().c_str()); NeuronTree nt = readSWC_file("/tmp/tmp_out_0.swc"); //nt.editable = false; callback.setSWC(curwin, nt); callback.updateImageWindow(curwin); callback.open3DWindow(curwin); //callback.getView3DControl(curwin)->setShowSurfObjects(2); //TestDialog dialog(callback, parent); //if (dialog.exec()!=QDialog::Accepted) return -1; //dialog.update(); //int i = dialog.i; //int c = dialog.channel; //Image4DSimple *p4DImage = callback.getImage(win_list[i]); //if(p4DImage->getCDim() <= c) {v3d_msg(QObject::tr("The channel isn't existed.")); return -1;} //V3DLONG sz[3]; //sz[0] = p4DImage->getXDim(); //sz[1] = p4DImage->getYDim(); //sz[2] = p4DImage->getZDim(); //unsigned char * inimg1d = p4DImage->getRawDataAtChannel(c); //v3dhandle newwin; //if(QMessageBox::Yes == QMessageBox::question(0, "", QString("Do you want to use the existing windows?"), QMessageBox::Yes, QMessageBox::No)) //newwin = callback.currentImageWindow(); //else //newwin = callback.newImageWindow(); //p4DImage->setData(inimg1d, sz[0], sz[1], sz[2], sz[3]); //callback.setImage(newwin, p4DImage); //callback.setImageName(newwin, QObject::tr("v3dneuron_tracing")); //callback.updateImageWindow(newwin); return 1; }