//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(); }
bool findedgeimg(V3DPluginCallback2 &callback, const V3DPluginArgList & input, V3DPluginArgList & output) { cout<<"Welcome to Label edge of a mask image"<<endl; if (output.size() != 1) return false; int method_code = 0; if (input.size()>=2) { vector<char*> paras = (*(vector<char*> *)(input.at(1).p)); if(paras.size() >= 1) method_code = atoi(paras.at(0)); } char * inimg_file = ((vector<char*> *)(input.at(0).p))->at(0); char * outimg_file = ((vector<char*> *)(output.at(0).p))->at(0); cout<<"method_code = "<<method_code<<endl; cout<<"inimg_file = "<<inimg_file<<endl; cout<<"outimg_file = "<<outimg_file<<endl; Image4DSimple *image = callback.loadImage(inimg_file); if (!image || !image->valid()) { cerr<<"load image "<<inimg_file<<" error!"<<endl; return false; } V3DLONG szx=image->getXDim(), szy=image->getYDim(), szz=image->getZDim(), szc=image->getCDim(); V3DLONG N = image->getTotalUnitNumber(); //create the output buffer unsigned char *outputData = 0; try { outputData = new unsigned char [N]; for (V3DLONG tmpi=0; tmpi<N; ++tmpi) outputData[tmpi] = 0; //preset to be all 0 } catch (...) { v3d_msg("Fail to allocate memory."); if (outputData) { delete []outputData; outputData=0; } return false; } Image4DSimple outputImage; outputImage.setData((unsigned char*)outputData, szx, szy, szz, szc, V3D_UINT8); Image4DProxy<Image4DSimple> outputIProxy(&outputImage); //now do computation { bool bset255 = (method_code==0) ? false : true; Image4DProxy<Image4DSimple> p(image); Image4DProxy_foreach(p, ix, iy, iz, ic) { double v = p.value_at(ix, iy, iz, ic); V3DLONG cx, cy, cz; bool bb=false; for (cz = iz-1; cz<iz+2; ++cz) { for (cy = iy-1; cy<iy+2; ++cy) { for (cx = ix-1; cx<ix+2; ++cx) { if (!p.is_inner(cx, cy, cz, ic)) continue; if (v!=p.value_at(cx, cy, cz, ic)) { *outputIProxy.at(ix, iy, iz, ic) = (bset255) ? 255 : v; bb = true; break; } } if (bb) break; } if (bb) break; } //note that all value had been preset as 0, thus no need to set as the background color in case not an edge point } }