bool open_fiji::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("openfiji")) { vector<char*> infiles, outfiles; if(input.size()==0) { cout<<"for usage type: vaa3d -x open_fiji -f help"<<endl; return false; } if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) { if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); } char * inimg_file = ((vector<char*> *)(input.at(0).p))->at(0); char * outimg_file = ((vector<char*> *)(output.at(0).p))->at(0); call_open_using_imagej(false, QString(inimg_file ),QString(outimg_file), callback); } else if (func_name == tr("help")) { cout<<"Usage : vaa3d -x open_fiji -f openfiji -i <input_file_name> -o <output_file_name> "<<endl; } else return false; return true; }
bool mostVesselTracerPlugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("MOST_trace")) { return autotrace(input, output,callback); } else if (func_name == tr("help")) { cout<<"Usage : v3d -x dllname -f MOST_trace -i <inimg_file> -p <ch> <th> <seed> <slip>"<<endl; cout<<endl; cout<<"ch the input channel value, start from 1, default 1"<<endl; cout<<"th the threshold value, default 20"<<endl; cout<<"seed window size of the seed, default 20"<<endl; cout<<"slip window size to slip from seed, default 20"<<endl; cout<<"The output swc file will be named automatically based on the input image file nmae"<<endl; cout<<endl; cout<<endl; } else return false; return true; }
bool SigenPlugin::dofunc( const QString &func_name, const V3DPluginArgList &input, V3DPluginArgList & /* output */, V3DPluginCallback2 &callback, QWidget *parent) { using std::vector; if (func_name == tr("trace")) { input_PARA PARA; vector<char *> *pinfiles = (input.size() >= 1) ? (vector<char *> *)input[0].p : 0; vector<char *> *pparas = (input.size() >= 2) ? (vector<char *> *)input[1].p : 0; vector<char *> infiles = (pinfiles != 0) ? *pinfiles : vector<char *>(); vector<char *> paras = (pparas != 0) ? *pparas : vector<char *>(); if (infiles.empty()) { fprintf(stderr, "Need input image. \n"); return false; } else { PARA.inimg_file = infiles[0]; } int k = 0; PARA.channel = ((int)paras.size() >= k + 1) ? atoi(paras[k]) : 1; k++; reconstruction_func(callback, parent, PARA, /* via_gui = */ false); } else if (func_name == tr("help")) { ////HERE IS WHERE THE DEVELOPERS SHOULD UPDATE THE USAGE OF THE PLUGIN printf("**** Usage of SIGEN tracing **** \n"); printf("vaa3d -x SIGEN -f trace -i <inimg_file> -p <channel> <other parameters>\n"); printf("inimg_file The input image\n"); printf("channel Data channel for tracing. Start from 1 (default 1).\n"); printf("outswc_file Will be named automatically based on the input image file name, so you don't have to specify it.\n\n"); } else { return false; } return true; }
bool processImage(V3DPluginCallback2 &callback, const V3DPluginArgList & input, V3DPluginArgList & output, unsigned int rotateflag) { cout<<"Welcome to Rotate image"<<endl; if (input.size() != 1 || output.size() != 1) return false; char * inimg_file = ((vector<char*> *)(input.at(0).p))->at(0); char * outimg_file = ((vector<char*> *)(output.at(0).p))->at(0); cout<<"rotateflag = "<<rotateflag<<endl; cout<<"inimg_file = "<<inimg_file<<endl; cout<<"outimg_file = "<<outimg_file<<endl; unsigned char * data1d = 0; V3DLONG in_sz[4]; int datatype; if(!simple_loadimage_wrapper(callback, inimg_file, data1d, in_sz, datatype)) { cerr<<"load image "<<inimg_file<<" error!"<<endl; return false; } unsigned char* outimg = 0; V3DLONG szx=in_sz[0], szy=in_sz[1], szz=in_sz[2], szc=in_sz[3]; switch (datatype) { case 1: rotateimage(data1d, in_sz, V3D_UINT8, rotateflag, outimg); break; case 2: rotateimage(data1d, in_sz, V3D_UINT16, rotateflag, outimg); break; case 4: rotateimage(data1d, in_sz, V3D_FLOAT32, rotateflag, outimg); break; default: v3d_msg("Invalid datatype."); if (data1d) {delete []data1d; data1d=0;} return false; } // save image switch(rotateflag) { case 1: case 2: in_sz[0]=szy; in_sz[1]=szx; simple_saveimage_wrapper(callback, outimg_file, (unsigned char *)outimg, in_sz, datatype); break; case 3: in_sz[0]=szx; in_sz[1]=szy; simple_saveimage_wrapper(callback, outimg_file, (unsigned char *)outimg, in_sz, datatype); break; default: break; } if (outimg) {delete []outimg; outimg =0;} if (data1d) {delete []data1d; data1d=0;} return true; }
bool swc2eswc_io(const V3DPluginArgList & input, V3DPluginArgList & output) { cout<<"Welcome to swc2eswc_io"<<endl; vector<char*>* inlist = (vector<char*>*)(input.at(0).p); vector<char*>* outlist = NULL; if(input.size() != 1) { printf("Please specify both input file name.\n"); return false; } QString fileOpenName = QString(inlist->at(0)); QString fileSaveName; QString tmp = fileOpenName; if (output.size()==0) { printf("No outputfile specified.\n"); tmp.chop(3); fileSaveName = tmp + "eswc"; } else if (output.size()==1) { outlist = (vector<char*>*)(output.at(0).p); fileSaveName = QString(outlist->at(0)); } else { printf("You have specified more than 1 output file.\n"); return false; } NeuronTree neuron; vector<V3DLONG> segment_id, segment_layer; if (fileOpenName.endsWith(".swc") || fileOpenName.endsWith(".SWC")) { neuron = readSWC_file(fileOpenName); segment_id, segment_layer; if (!swc2eswc(neuron,segment_id, segment_layer)) { v3d_msg("Cannot convert swc to eswc.", 0); return false; } } else { v3d_msg("The file type you specified is not supported. Please check.", 0); return false; } if (!export_eswc(neuron,segment_id,segment_layer,qPrintable(fileOpenName),qPrintable(fileSaveName))) { v3d_msg("fail to write the output eswc file.", 0); return false; } return true; }
bool retype_swc::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, paras, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) paras = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("retype")) { cout<<"Welcome to swc retyping plugin"<<endl; if(infiles.empty()) { cerr<<"Need input swc file"<<endl; return false; } QString inswc_file = infiles[0]; int k=0; int type = (paras.size() >= k+1) ? atoi(paras[k]) : 3; k++;//0; QString outswc_file; if(!outfiles.empty()) outswc_file = outfiles[0]; else outswc_file = inswc_file + "_retyped.swc"; cout<<"inswc_file = "<<inswc_file.toStdString().c_str()<<endl; cout<<"node type = "<<type<<endl; cout<<"outswc_file = "<<outswc_file.toStdString().c_str()<<endl; NeuronTree nt; nt = readSWC_file(inswc_file); for(V3DLONG i = 0; i < nt.listNeuron.size(); i++) { if(nt.listNeuron[i].parent == -1) nt.listNeuron[i].type = 1; else nt.listNeuron[i].type = type; } if (!export_list2file(nt.listNeuron,outswc_file,inswc_file)) { v3d_msg("fail to write the output swc file."); return false; } } else if (func_name == tr("help")) { cout<<"Usage : v3d -x dllname -f retype -i <inswc_file> -o <outswc_file> -p <type>"<<endl; cout<<endl; } else return false; return true; }
bool file_transform::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("affineImage")) { qDebug()<<"==== affine and combine images ===="; if(infiles.size()!=3 || outfiles.size()!=1){ qDebug()<<"ERROR: please set input and output!"; printHelp(); return false; } QString fname_img_tar=((vector<char*> *)(input.at(0).p))->at(0); QString fname_img_sub=((vector<char*> *)(input.at(0).p))->at(1); QString fname_amat=((vector<char*> *)(input.at(0).p))->at(2); QString fname_output=((vector<char*> *)(output.at(0).p))->at(0); //init parameters bool b_channelSeperate = false; bool b_negativeShift = true; int interpMethod = 0; if(input.size() >= 2){ vector<char*> paras = (*(vector<char*> *)(input.at(1).p)); if(paras.size()>0){ int tmp=atoi(paras.at(0)); if(tmp==1) interpMethod = 1; } if(paras.size()>1){ int tmp=atoi(paras.at(1)); if(tmp==0) b_negativeShift = false; } if(paras.size()>2){ int tmp=atoi(paras.at(2)); if(tmp==1) b_channelSeperate = true; } } doAffineImage(callback, fname_img_tar, fname_img_sub, fname_amat, fname_output, interpMethod, b_negativeShift, b_channelSeperate); } else if (func_name == tr("help")) { printHelp(); } else return false; return true; }
bool RivuletPlugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("tracing_func")) { bool bmenu = false; input_PARA PARA; vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); if(infiles.empty()) { fprintf (stderr, "Need input image. \n"); return false; } else PARA.inimg_file = infiles[0]; int k=0; PARA.channel = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.threshold = (paras.size() >= k+1) ? atoi(paras[k]) : 10; k++; PARA.stepsize = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.gap = (paras.size() >= k+1) ? atoi(paras[k]) : 15; k++; PARA.dumpbranch = (paras.size() >= k+1) ? atoi(paras[k]) : 0; k++; PARA.connectrate = (paras.size() >= k+1) ? atof(paras[k]) : 1.5; k++; PARA.percentage = (paras.size() >= k+1) ? atof(paras[k]) : 0.98; k++; if (PARA.percentage > 1.0) PARA.percentage = 1.0; PARA.sigma = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.alpha_one = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.alpha_two = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; reconstruction_func(callback,parent,PARA,bmenu); } else if (func_name == tr("help")) { printf("**** Usage of Rivulet tracing **** \n"); printf("vaa3d -x Rivulet -f tracing_func -i <inimg_file> -p <channel> <threshold> <stepsize> <gap> <dumpbranch> <connectrate> <percentage>\n"); printf("inimg_file\tThe input image\n"); printf("channel\tData channel for tracing. Start from 1 (default 1).\n"); printf("threshold\tThe background threshold for segmentation (default 10).\n"); printf("stepsize\tThe step size of gradient descent tracing (default 1).\n"); printf("gap\tThe gap allowed for steps on background voxels. Useful for noisy images (default 15)\n"); printf("dumpbranch\tWhether the unconnected branches will be dumpped. (default 0)\n"); printf("connectrate\tBranch terminis within connectrate*(radius+3) will be connected to the trunk. (default 1.5)\n"); printf("percentage\tThe converage expected on the binary image before stopping tracing. (default 0.98)\n"); printf("outswc_file\tWill be named automatically based on the input image file name, so you don't have to specify it.\n\n"); } else return false; return true; }
bool neurontracing_rotation::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("tracing_func")) { bool bmenu = false; input_PARA PARA; vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); if(infiles.empty()) { fprintf (stderr, "Need input image. \n"); return false; } PARA.inimg_file = infiles[0]; PARA.image = 0; int k=0; // QString inmarker_file = paras.empty() ? "" : paras[k]; if(inmarker_file == "NULL") inmarker_file = ""; k++; PARA.rotation_degree = (paras.size() >= k+1) ? atoi(paras[k]) : 36; k++; PARA.channel = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.bkg_thresh = (paras.size() >= k+1) ? atoi(paras[k]) : 10; if(PARA.bkg_thresh == atoi("AUTO")) PARA.bkg_thresh = -1;k++; PARA.b_256cube = (paras.size() >= k+1) ? atoi(paras[k]) : 0; k++; PARA.b_RadiusFrom2D = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.is_gsdt = (paras.size() >= k+1) ? atoi(paras[k]) : 0; k++; PARA.is_break_accept = (paras.size() >= k+1) ? atoi(paras[k]) : 0; k++; PARA.length_thresh = (paras.size() >= k+1) ? atoi(paras[k]) : 5; k++; reconstruction_func(callback,parent,PARA,bmenu); } else if (func_name == tr("help")) { ////HERE IS WHERE THE DEVELOPERS SHOULD UPDATE THE USAGE OF THE PLUGIN printf("**** Usage of neurontracing_rotation tracing **** \n"); printf("vaa3d -x neurontracing_rotation -f tracing_func -i <inimg_file> -p <channel> <other parameters>\n"); printf("inimg_file The input image\n"); printf("channel Data channel for tracing. Start from 1 (default 1).\n"); printf("outswc_file Will be named automatically based on the input image file name, so you don't have to specify it.\n\n"); } else return false; return true; }
bool NeuroStalker::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("tracing_func")) { bool bmenu = false; input_PARA PARA; vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); if(infiles.empty()) { fprintf (stderr, "Need input image. \n"); return false; } else PARA.inimg_file = infiles[0]; int k=0; PARA.channel = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.preprocessing = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.unittest = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.step = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.stepsize = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; PARA.threshold = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; cout<<"Input step test: "<<PARA.step<<endl; reconstruction_func(callback,parent,PARA,bmenu); } else if (func_name == tr("help")) { ////HERE IS WHERE THE DEVELOPERS SHOULD UPDATE THE USAGE OF THE PLUGIN printf("**** Usage of NeuroStalker tracing **** \n"); printf("vaa3d -x NeuroStalker -f tracing_func -i <inimg_file> -p <channel> <preprocessing> <run unit-tests>\n"); printf("inimg_file The input image\n"); printf("channel Data channel for tracing. Start from 1 (default 1).\n"); printf("preprocessing The preprocessing flag - 1: Crop Only; 2: Downsample; 3: Downsample and crop; \n"); printf("run unit-tests - 1: Run Tracing Only; 2: Run unit-tests only; 3: Run Both Unit Tests and Tracing; \n"); printf("outswc_file Will be named automatically based on the input image file name, so you don't have to specify it.\n\n"); } else return false; return true; }
bool resample_swc(const V3DPluginArgList & input, V3DPluginArgList & output) { cout<<"Welcome to resample_swc"<<endl; vector<char*>* inlist = (vector<char*>*)(input.at(0).p); vector<char*>* outlist = NULL; vector<char*>* paralist = NULL; if(input.size() != 2) { printf("Please specify both input file and step length parameter.\n"); return false; } paralist = (vector<char*>*)(input.at(1).p); if (paralist->size()!=1) { printf("Please specify only one parameter - the resampling step length.\n"); return false; } double step = atof(paralist->at(0)); QString fileOpenName = QString(inlist->at(0)); QString fileSaveName; if (output.size()==0) { printf("No outputfile specified.\n"); fileSaveName = fileOpenName + "_resampled.swc"; } else if (output.size()==1) { outlist = (vector<char*>*)(output.at(0).p); fileSaveName = QString(outlist->at(0)); } else { printf("You have specified more than 1 output file.\n"); return false; } NeuronTree nt; if (fileOpenName.toUpper().endsWith(".SWC") || fileOpenName.toUpper().endsWith(".ESWC")) nt = readSWC_file(fileOpenName); NeuronTree result = resample(nt,step); if (!export_list2file(result.listNeuron, fileSaveName, fileOpenName)) { printf("fail to write the output swc file.\n"); return false; } return true; }
bool border_tips::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("help")) { qDebug()<<"No do func available."; } else return false; return true; }
bool markertree::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("help")) { v3d_msg("To be implemented"); } else return false; return true; }
bool BlastNeuronPlugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("global_retrieve")) { return(global_retrieve_main(input, output)); } else if (func_name == tr("local_alignment")) { return(local_alignment_main(input, output)); } else if (func_name == tr("batch_compute")) { return (batch_compute_main(input, output)); } else if (func_name == tr("pre_processing")) { return (pre_processing_main(input, output)); } else if (func_name == tr("inverse_projection")) { return (inverse_projection_main(input, output)); } else { printf("\nBlastNeuron Plugin: rapid global retrieval and local alignent of 3D neuron morphologies. This plugin also includes pre-processing, inverse projection and batch feature computation. by Yinan Wan.\n\n"); printf("Functions:\n"); printf("\t pre_processing prune, resample and align neuron swcs.\n"); printf("\t global_retrieve given a query neuron, retrieve morphologically similar neurons from a neuron feature database.\n"); printf("\t local_alignment point to point alignment of two morphologically similar neurosn.\n"); printf("\t batch_compute generate neuron feature database (.nfb) file first to speed up neuron retrieve\n"); printf("\t invert_projection find an optimal affine transform between neuron structures regardless of topology.\n\n"); printf("Example: \n"); printf("\t vaa3d -x blastneuron -f pre_processing -p \"#i input.swc #o result.swc #l 3 #s 2 #r 1 \"\n"); printf("\t vaa3d -x blastneuron -f batch_compute -p \"#i mydatabase.ano #o features.nfb\"\n"); printf("\t vaa3d -x blastneuron -f global_retrieve -p \"#d features.nfb #q query.swc #n 10 #m 1,2,4 #o retrieve.ano\"\n"); printf("\t vaa3d -x blastneuron -f local_alignment -p \"#t target.swc #s subject.swc #o match.swc\"\n"); printf("\t vaa3d -x blastneuron -f inverse_projection -p \"#i target.swc #o target_invp.swc\"\n\n"); printf("Type vaa3d -x blastneuron -f <function_name> for instructions to run individual functions.\n"); printf("Alternatively, you can run a query search from the neuron feature database with a bash script: try \"sh blastneuron_plugin.sh\" for detailed instruction\n\n"); return true; } }
bool AnisoDiffPlugin_littlequick::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("anisodiff_littlequick_menu")) { cout<<"============== Welcome to anisodiff function ================="<<endl; bool bmenu = false; input_PARA PARA; vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); if(infiles.empty()) { fprintf (stderr, "Need input image. \n"); return false; } else PARA.inimg_file = infiles[0]; anisodiff_func(callback,parent,PARA,bmenu); } else { printHelp(); } return true; }
bool neuronScore::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("calculate_score")) { vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> * poutfiles = (output.size() >= 1) ? (vector<char*> *) output[0].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); vector<char*> outfiles = (poutfiles != 0) ? * poutfiles : vector<char*>(); if(infiles.size()<2) { fprintf (stderr, "Need input image and swc. \n"); printHelp(); return false; } if(outfiles.empty()) { fprintf (stderr, "Need output file name. \n"); printHelp(); return false; } int k=0; int scoreType = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; float radiusFactor = (paras.size() >= k+1) ? atof(paras[k]) : 2; k++; doCalculateScore(callback, infiles[0],infiles[1],outfiles[0],scoreType,radiusFactor,0); } else if (func_name == tr("help")) { printHelp(); } else return false; return true; }
bool median_swc_func(const V3DPluginArgList & input, V3DPluginArgList & output) { if(input.size()==0) return false; //parsing input vector<char *> * inlist = (vector<char*> *)(input.at(0).p); if (inlist->size() == 0) { cerr<<"You must specify input linker or swc files"<<endl; return false; } V3DLONG neuronNum = 0; vector<NeuronTree> nt_list; QString qs_linker; QStringList nameList; for (int i=0;i<inlist->size();i++) { qs_linker = QString(inlist->at(i)); if (qs_linker.toUpper().endsWith(".ANO")) { cout<<"(0). reading a linker file."<<endl; P_ObjectFileType linker_object; if (!loadAnoFile(qs_linker,linker_object)) { fprintf(stderr,"Error in reading the linker file.\n"); return 1; } nameList = linker_object.swc_file_list; neuronNum += nameList.size(); for (V3DLONG i=0;i<neuronNum;i++) { NeuronTree tmp = readSWC_file(nameList.at(i)); nt_list.push_back(tmp); } } else if (qs_linker.toUpper().endsWith(".SWC")) { cout<<"(0). reading an swc file"<<endl; NeuronTree tmp = readSWC_file(qs_linker); nt_list.push_back(tmp); neuronNum++; } } cout << "There are "<<nt_list.size() <<" input neurons."<<endl; int idx = median_swc(nt_list); if (idx <0){ cerr << "error in median_swc()" << endl; return false; } cout<<"Median swc is " << idx << endl; return true; }
bool nctuTW::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("tracing_func")) { bool bmenu = false; input_PARA PARA; vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); if(infiles.empty()) { fprintf (stderr, "Need input image. \n"); return false; } else PARA.inimg_file = infiles[0]; int k=0; PARA.inmarker_file = paras.empty() ? "" : paras[k]; if(PARA.inmarker_file == "NULL") PARA.inmarker_file = ""; k++; PARA.threshold = (paras.size() >= k+1) ? atof(paras[k]) : 0.9; reconstruction_func(callback,parent,PARA,bmenu); } else if (func_name == tr("help")) { ////HERE IS WHERE THE DEVELOPERS SHOULD UPDATE THE USAGE OF THE PLUGIN printf("**** Usage of nctuTW tracing **** \n"); printf("vaa3d -x nctuTW -f tracing_func -i <inimg_file> -p <inmarker_file> <threshold>\n"); printf("inimg_file The input image\n"); printf("inmarker_file If no input marker file, please set this para to NULL and it will detect soma automatically.\n"); printf("threshold Default 0.9, otherwise the threshold (from 0 to 1) specified by a user will be used.\n"); printf("outswc_file Will be named automatically based on the input image file name, so you don't have to specify it.\n\n"); } else return false; return true; }
bool v3dneuron_tracing(const V3DPluginArgList & input, V3DPluginArgList & output) { cout<<"Welcome to v3dneuron_tracing"<<endl; if(input.size() != 2 || output.size() != 1) return false; char * paras = 0; if(((vector<char*> *)(input.at(1).p))->empty()){paras = new char[1]; paras[0]='\0';} else paras = (*(vector<char*> *)(input.at(1).p)).at(0); cout<<"paras : "<<paras<<endl; for(int i = 0; i < strlen(paras); i++) { if(paras[i] == '#') paras[i] = '-'; } cout<<"paras : "<<paras<<endl; cout<<string("v3dneuron_tracing ").append(paras).c_str()<<endl; system(string("v3dneuron_tracing ").append(paras).c_str()); return true; }
bool SWCRadiusPlugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if (func_name == tr("neuron_radius")) { if(infiles.size() != 2 && infiles.size() != 3) { cerr<<"Invalid input"<<endl; return false; } string inimg_file = infiles[0]; string inswc_file = infiles[1]; string outswc_file = (infiles.size() == 3) ? infiles[2] : ""; if(outswc_file == "") outswc_file = inswc_file + ".out.swc"; double bkg_thresh = (inparas.size() >= 1) ? atof(inparas[0]) : 40; bool is_2d = (inparas.size() == 2) ? atoi(inparas[1]) : 0; cout<<"inimg_file = "<<inimg_file<<endl; cout<<"inswc_file = "<<inswc_file<<endl; cout<<"outswc_file = "<<outswc_file<<endl; cout<<"bkg_thresh = "<<bkg_thresh<<endl; cout<<"is2d = "<< (int)is_2d <<endl; unsigned char * inimg1d = 0; V3DLONG * in_sz = 0; int datatype; if(!loadImage((char*)inimg_file.c_str(), inimg1d, in_sz, datatype)) return false; vector<MyMarker*> inswc = readSWC_file(inswc_file); if(inswc.empty()) return false; for(int i = 0; i < inswc.size(); i++) { MyMarker * marker = inswc[i]; if(is_2d) marker->radius = markerRadiusXY(inimg1d, in_sz, *marker, bkg_thresh); else marker->radius = markerRadius(inimg1d, in_sz, *marker, bkg_thresh); //printf("2d=%5.3f \t 3d=%5.3f\n", markerRadiusXY(inimg1d, in_sz, *marker, bkg_thresh), // markerRadius(inimg1d, in_sz, *marker, bkg_thresh)); } saveSWC_file(outswc_file, inswc); cout<<"The output swc is saved to "<<outswc_file<<endl; for(int i = 0; i < inswc.size(); i++) delete inswc[i]; if(inimg1d){delete [] inimg1d; inimg1d = 0;} if(in_sz){delete [] in_sz; in_sz = 0;} } else //if (func_name == tr("help")) { cout<<"v3d -x <plugin_dll> -f neuron_radius -i <inimg_file> <inswc_file> -p <threshold> [<is2d>]" <<endl <<"The output will be appended .out.swc automatically" <<endl; } return true; }
bool smartTrace_plugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("tracing_func")) { bool bmenu = false; input_PARA PARA; vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); if(infiles.empty()) { fprintf (stderr, "Need input image. \n"); return false; } else PARA.inimg_file = infiles[0]; int k=0; PARA.channel = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; reconstruction_func(callback,parent,PARA,bmenu); } else if(func_name == tr("selfCorrection")) { vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> * poutfiles = (output.size() >= 1) ? (vector<char*> *) output[0].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); vector<char*> outfiles = (poutfiles != 0) ? * poutfiles : vector<char*>(); if(infiles.size()<2) { fprintf (stderr, "Need input image and swc file. \n"); return false; } if(outfiles.empty()) { fprintf (stderr, "Need output file. \n"); return false; } if(paras.empty()) { fprintf (stderr, "Need confidential score file. \n"); return false; } nt_selfcorrect_func tracefunc; tracefunc.correct_tracing(infiles.at(0), infiles.at(1), paras.at(0), outfiles.at(0), &callback); } else if (func_name == tr("smartTrace")) { bool bmenu = false; input_PARA PARA; vector<char*> * pinfiles = (input.size() >= 1) ? (vector<char*> *) input[0].p : 0; vector<char*> * pparas = (input.size() >= 2) ? (vector<char*> *) input[1].p : 0; vector<char*> infiles = (pinfiles != 0) ? * pinfiles : vector<char*>(); vector<char*> paras = (pparas != 0) ? * pparas : vector<char*>(); if(infiles.empty()) { fprintf (stderr, "Need input image. \n"); return false; } else PARA.inimg_file = infiles[0]; int k=0; PARA.channel = (paras.size() >= k+1) ? atoi(paras[k]) : 1; k++; nt_selfcorrect_func tracefunc; tracefunc.smart_tracing(PARA.inimg_file,PARA.inimg_file+"_smartTracing",&callback); } else if (func_name == tr("help")) { ////HERE IS WHERE THE DEVELOPERS SHOULD UPDATE THE USAGE OF THE PLUGIN printf("\n\n**** Usage of smartTrace tracing **** \n"); printf("vaa3d -x smartTrace -f selfCorrection -i <inimg_file> <inswc_file> -o <output> -p <score.txt> \n"); printf("inimg_file The input image\n"); printf("inswc_file The input tracing\n"); printf("score.txt Confidential score calculated by plugin: calculate_reliability_score.\n"); printf("\n\nvaa3d -x smartTrace -f smartTrace -i <inimg_file> -p <channel>\n"); printf("inimg_file The input image\n"); printf("channel Data channel for tracing. Start from 1 (default 1).\n"); printf("outswc_file Will be named automatically based on the input image file name, so you don't have to specify it.\n\n"); } else return false; return true; }
bool ITilingPlugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("help")) { printf("\nUsage: v3d -x imageTiling.dylib -f itiling -i <input_image_file> -o <output_images_prefix_string> \n"); return true; } else if (func_name == tr("itiling")) { // subpixel translation registration based on pixel-level translation estimation if(input.size()<1) return false; // no inputs vector<char*> * infilelist = (vector<char*> *)(input.at(0).p); vector<char*> * paralist; vector<char*> * outfilelist; if(infilelist->empty()) { //print Help info printf("\nUsage: v3d -x imageTiling.dylib -f itiling -i <input_image_file> -o <output_images_prefix_string> \n"); return true; } char * infile = infilelist->at(0); // input_image_folder char * paras = NULL; // parameters char * outfile = NULL; // output_image_file if(output.size()>0) { outfilelist = (vector<char*> *)(output.at(0).p); outfile = outfilelist->at(0);} // specify output if(input.size()>1) { paralist = (vector<char*> *)(input.at(1).p); paras = paralist->at(0);} // parameters // init int channel1 = 0; bool img_show = true; // save stitching file bool success = false; ImagePixelType imgdatatype; V3DLONG cdim; // parsing parameters if(paras) { int argc = 0; int len = strlen(paras); int posb[200]; char * myparas = new char[len]; strcpy(myparas, paras); for(int i = 0; i < len; i++) { if(i==0 && myparas[i] != ' ' && myparas[i] != '\t') { posb[argc++] = i; } else if((myparas[i-1] == ' ' || myparas[i-1] == '\t') && (myparas[i] != ' ' && myparas[i] != '\t')) { posb[argc++] = i; } } char ** argv = new char* [argc]; for(int i = 0; i < argc; i++) { argv[i] = myparas + posb[i]; } for(int i = 0; i < len; i++) { if(myparas[i]==' ' || myparas[i]=='\t') myparas[i]='\0'; } char* key; for(int i=0; i<argc; i++) { if(i+1 != argc) // check that we haven't finished parsing yet { key = argv[i]; qDebug()<<">>key ..."<<key; if (*key == '#') { while(*++key) { if (!strcmp(key, "c")) { channel1 = atoi( argv[i+1] ) - 1; // red 1 green 2 blue 3 i++; } else if (!strcmp(key, "s")) { img_show = atoi( argv[i+1] )?true:false; i++; } else { cout<<"parsing ..."<<key<<i<<"Unknown command. Type 'v3d -x plugin_name -f function_name' for usage"<<endl; return false; } } } else { cout<<"parsing ..."<<key<<i<<"Unknown command. Type 'v3d -x plugin_name -f function_name' for usage"<<endl; return false; } } } // error check if(channel1<0) { cout<<"illegal input parameters"<<endl; return false; } //free space if (argv) {delete []argv; argv=0;} if (myparas) {delete []myparas; myparas=0;} } // get stitch configuration //QDir myDir(infile); // group stitch in subspace int start_t = clock(); // int datatype_tile = 0; // assume all tiles with the same datatype V3DLONG *sz_relative = 0; unsigned char* relative1d = 0; if(QFile(QString(infile)).exists()) { if (!loadImage(const_cast<char *>(infile), relative1d, sz_relative, datatype_tile)) { if (!do_blockwise_read(const_cast<char *>(infile)), outfile) { fprintf(stderr, "Error happens in reading the subject file [%s]. Exit. \n",infile); return false; } else { v3d_msg("Succeed!"); return true; } } } else { v3d_msg("The input file is not supported!",0); return false; } // switch (datatype_tile) { case V3D_UINT8: if (!imgtiling<unsigned char, V3DLONG>((unsigned char *)relative1d, sz_relative[0], sz_relative[1], sz_relative[2], sz_relative[3], QString(outfile), datatype_tile)) { v3d_msg("Fail to call function imgtiling (8bit)! \n", 0); return false; } break; case V3D_UINT16: if (!imgtiling<unsigned short, V3DLONG>((unsigned short *)relative1d, sz_relative[0], sz_relative[1], sz_relative[2], sz_relative[3], QString(outfile), datatype_tile)) { v3d_msg("Fail to call function imgtiling (16bit)! \n", 0); return false; } break; case V3D_FLOAT32: if (!imgtiling<float, V3DLONG>((float *)relative1d, sz_relative[0], sz_relative[1], sz_relative[2], sz_relative[3], QString(outfile), datatype_tile)) { v3d_msg("Fail to call function imgtiling (32bit)! \n", 0); return false; } break; default: v3d_msg("Currently this program only support UINT8, UINT16, and FLOAT32 datatype.\n",0); return false; } cout<<"time elapse ... "<<clock()-start_t<<endl; return true; } else { v3d_msg("\nWrong function specified.\n",0); return false; } return true; }
bool eswc2swc_io(const V3DPluginArgList & input, V3DPluginArgList & output) { cout<<"Welcome to eswc2swc_io"<<endl; vector<char*>* inlist = (vector<char*>*)(input.at(0).p); vector<char*>* outlist = NULL; if(input.size() != 1) { printf("Please specify both input file name.\n"); return false; } QString fileOpenName = QString(inlist->at(0)); QString fileSaveName; QString tmp = fileOpenName; if (output.size()==0) { printf("No outputfile specified.\n"); tmp.chop(4); fileSaveName = tmp + "swc"; } else if (output.size()==1) { outlist = (vector<char*>*)(output.at(0).p); fileSaveName = QString(outlist->at(0)); } else { printf("You have specified more than 1 output file.\n"); return false; } NeuronTree neuron; vector<V3DLONG> segment_id, segment_layer; vector<double> feature; if (fileOpenName.endsWith(".eswc") || fileOpenName.endsWith(".ESWC")) { neuron = read_eswc(segment_id, segment_layer, feature, fileOpenName); if (!swc2eswc(neuron,segment_id, segment_layer)) { v3d_msg("Cannot convert eswc to swc.\n"); return false; } } else { v3d_msg("The file type you specified is not supported. Please check."); return false; } int ret = QMessageBox::Yes; if (check_eswc(neuron, segment_id, segment_layer)==-1) { v3d_msg("WARNING: Something is wrong with the eswc file", 0); v3d_msg("But we still put convert it to swc format", 0); } QString fileDefaultName = fileOpenName; fileDefaultName.chop(4); fileDefaultName += QString("swc"); //write new SWC to file if (!export_swc(neuron,qPrintable(fileSaveName))) { v3d_msg("fail to write the output swc file.", 0); return false; } return true; }
bool batch_compute_main(const V3DPluginArgList & input, V3DPluginArgList & output) { printf("\nwelcome to batch_compute\n"); vector<char*>* inlist = (vector<char*>*)(input.at(0).p); vector<char*>* outlist = NULL; vector<char*>* paralist = NULL; if(input.size() != 2) { printf("Please specify parameter set.\n"); printHelp_batch_compute(); return false; } paralist = (vector<char*>*)(input.at(1).p); if (paralist->size()!=1) { printf("Please specify all paramters in one text string.\n"); printHelp_batch_compute(); return false; } char * paras = paralist->at(0); int argc = 1; enum {kArgMax = 64}; char *argv[kArgMax]; //parsing parameters if (paras) { int len = strlen(paras); for (int i=0;i<len;i++) { if (paras[i]=='#') paras[i] = '-'; } char* pch = strtok(paras, " "); while (pch && argc<kArgMax) { argv[argc++] = pch; pch = strtok(NULL, " "); } } else printHelp_batch_compute(); //read arguments char *dfile_database = NULL; char *dfile_result = NULL; double step_size = 2; int c; static char optstring[] = "h:i:o:"; opterr = 0; while ((c = getopt(argc, argv, optstring))!=-1) { switch (c) { case 'h': printHelp_batch_compute(); return 0; break; case 'i': if (strcmp(optarg,"(null)")==0 || optarg[0]=='-') { fprintf(stderr, "Found illegal or NULL parameter for the option -i.\n"); return 1; } dfile_database = optarg; break; case 'o': if (strcmp(optarg,"(null)")==0 || optarg[0]=='-') { fprintf(stderr, "Found illegal or NULL parameter for the option -o.\n"); return 1; } dfile_result = optarg; break; case '?': fprintf(stderr,"Unknown option '-%c' or incomplete argument lists.\n",optopt); return 1; break; } } //read database file QStringList nameList, filePathList; V3DLONG neuronNum; QString qs_database(dfile_database); QList<double*> morph_list, gmi_list; qs_database = qs_database.simplified(); if (qs_database.endsWith(".ano") || qs_database.endsWith(".ANO")) { printf("(0). reading a linker file.\n"); P_ObjectFileType linker_object; if (!loadAnoFile(QString(dfile_database),linker_object)) { fprintf(stderr,"Error in reading the linker file.\n"); return 1; } nameList = linker_object.swc_file_list; neuronNum = nameList.size(); for (V3DLONG i=0;i<neuronNum;i++) { NeuronTree tmp = readSWC_file(nameList.at(i)); printf(qPrintable("calculating features for" + tmp.file +".\n")); filePathList.append(tmp.file); // it makes more sense to run pre_processing seperately, so that the pre_processed steps can be adjusted (tuning step size), saved and verified. //NeuronTree tmp_preprocessed = pre_process(tmp, step_size); double * feature_morph = new double[21]; double * feature_gmi = new double[14]; computeFeature(tmp, feature_morph); computeGMI(tmp, feature_gmi); morph_list.append(feature_morph); gmi_list.append(feature_gmi); } } else { fprintf(stderr, "the reference file/list you specified is not supported.\n"); return 1; } QString outfile(dfile_result); if (!dfile_result) { outfile = qs_database + "features.nfb"; } //if sepcified format is csv file if (outfile.right(4) == ".csv") { FILE * fp; fp = fopen(qPrintable(outfile), "w"); QString header = "swc_file,num_nodes,soma_surface,num_stems," "num_bifurcations,num_branches,num_of_tips," "overall_x_span,overall_y_span,overall_z_span," "average_diameter,total_length,total_surface," "total_volume,max_euclidean_distance,max_path_distance," "max_branch_order,average_contraction,average_fragmentation," "parent_daughter_ratio,bifurcation_angle_local," "bifurcation_angle_remote," "moment1,moment2,moment3,moment4,moment5,moment6," "moment7,moment8,moment9,moment10,moment11,moment12," "moment13,ave_R\n"; fprintf(fp,qPrintable(header)); for (V3DLONG i=0;i<neuronNum;i++) { fprintf(fp, qPrintable(filePathList[i])); for (int j=0;j<21;j++) fprintf(fp,", %.8f", morph_list[i][j]); for (int j=0;j<14;j++) fprintf(fp,", %.8f", gmi_list[i][j]); fprintf(fp,"\n"); } fclose(fp); } else{ //output a neuron featurebase (.nfb) file FILE * fp; fp = fopen(qPrintable(outfile), "w"); for (V3DLONG i=0;i<neuronNum;i++) { fprintf(fp, qPrintable("SWCFILE=" + filePathList[i])); fprintf(fp, "\n"); for (int j=0;j<21;j++) fprintf(fp,"%.8f\t", morph_list[i][j]); fprintf(fp,"\n"); for (int j=0;j<14;j++) fprintf(fp,"%.8f\t", gmi_list[i][j]); fprintf(fp,"\n"); } fclose(fp); } for (V3DLONG i=0;i<neuronNum;i++) { if (morph_list[i]) {delete []morph_list[i]; morph_list[i]=NULL;} if (gmi_list[i]) {delete []gmi_list[i]; gmi_list[i]=NULL;} } return true; }
bool profile_swc_func(V3DPluginCallback2 &callback, const V3DPluginArgList & input, V3DPluginArgList & output) { vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) inparas = *((vector<char*> *)input.at(1).p); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); if(infiles.size() != 2 && infiles.size() != 3) { cerr<<"Invalid input"<<endl; return false; } QString imageFileName = QString(infiles[0]); QString swcFileName = QString(infiles[1]); QString output_csv_file; if(!outfiles.empty()) output_csv_file = QString(outfiles[0]); else output_csv_file = swcFileName + ".csv"; float dilate_ratio = (inparas.size() >= 1) ? atof(inparas[0]) : 3.0; int flip = (inparas.size() >= 2) ? atoi(inparas[1]) : 1; int invert = (inparas.size() >= 3) ? atoi(inparas[2]) : 1; cout<<"inimg_file = "<< imageFileName.toStdString()<<endl; cout<<"inswc_file = "<< swcFileName.toStdString()<<endl; cout<<"output_file = "<< output_csv_file.toStdString()<<endl; cout<<"dilate_ratio = "<< dilate_ratio<<endl; cout<<"flip y = "<< flip <<endl; cout<<"invert intensity = "<< invert <<endl; NeuronTree neuronTree; if (swcFileName.endsWith(".swc") || swcFileName.endsWith(".SWC")) { neuronTree = readSWC_file(swcFileName); } else { cout<<"The file type you specified is not supported."<<endl; return false; } Image4DSimple *image = callback.loadImage((char * )imageFileName.toStdString().c_str()); QList<IMAGE_METRICS> result_metrics = intensity_profile(neuronTree, image, dilate_ratio,flip,invert, callback); IMAGE_METRICS m_stats = result_metrics[0]; /* ENSEMBLE_METRICS m_stats = stats_ensemble(result_metrics); */ cout << "Overall Contrast-to-Background Ratio:" << m_stats.cnr << "\n" << "Overall Dynamic Range:"<< m_stats.dy << "\n" << "Mean BG Intensity:" << m_stats.bg_mean << ", with std = " << m_stats.bg_std << "\n" << "Mean FG Intensity:" << m_stats.fg_mean << ", with std = " << m_stats.fg_std << "\n" << "Mean Tubularity:" << m_stats.tubularity_mean << ", with std = " << m_stats.tubularity_std << "\n" << endl; if (result_metrics.isEmpty()) { cout<<"Error in intensity_profile() !"<<endl; return false; } else{ if (!writeMetrics2CSV(result_metrics, output_csv_file)) { cout<< "error in writeMetrics2CSV()" <<endl; } } cout << "Segment type-specific screening metrics are exported in: " << output_csv_file.toStdString() <<endl; return true; }
bool processImage(V3DPluginCallback2 &callback, const V3DPluginArgList & input, V3DPluginArgList & output) { if(input.size() < 1 || output.size() != 1) return false; V3DLONG c = -1; if (input.size()>=2) { vector<char*> paras = *(vector<char*> *)(input.at(1).p); if(paras.size() >= 1) c = atoi(paras.at(0)); } if (c<0) { v3d_msg("You explicitly or implicitly specified a channel number < 0, which means split-all-channels. \n",0); } char * inimg_file = ((vector<char*> *)(input.at(0).p))->at(0); char * outimg_file = ((vector<char*> *)(output.at(0).p))->at(0); cout<<"channel = "<<c<<endl; cout<<"inimg_file = "<<inimg_file<<endl; cout<<"outimg_file = "<<outimg_file<<endl; bool b_res=false; unsigned char * data1d = 0; V3DLONG in_sz[4]; void* outimg = 0; V3DLONG cb, ce, k; int datatype; if(!simple_loadimage_wrapper(callback, inimg_file, data1d, in_sz, datatype)) { cerr<<"load image "<<inimg_file<<" error!"<<endl; return false; } if (c>=in_sz[3]) { v3d_msg("The specified channel is not valid. Do nothing.", 0); goto Label_exit; } if (c<0) {cb=0; ce=in_sz[3]-1;} else {cb = ce = c;} for (k=cb; k<=ce; k++) { printf("\n... processing [%d] channel now...\n", k); switch(datatype) { case 1: b_res = extract_a_channel(data1d, in_sz, k, outimg); break; case 2: b_res = extract_a_channel((unsigned short int *)data1d, in_sz, k, outimg); break; case 4: b_res = extract_a_channel((float *)data1d, in_sz, k, outimg); break; default: b_res = false; v3d_msg("Right now this plugin supports only UINT8/UINT16/FLOAT32 data. Do nothing."); goto Label_exit; } // save image V3DLONG oldc = in_sz[3]; in_sz[3]=1; if (cb==ce) simple_saveimage_wrapper(callback, outimg_file, (unsigned char *)outimg, in_sz, datatype); else simple_saveimage_wrapper(callback, qPrintable(QString("").setNum(k).prepend("_C").prepend(outimg_file).append(".v3draw")), (unsigned char *)outimg, in_sz, datatype); // in_sz[3] = oldc; //this sentence is important printf("b_res=[%s]\n", (b_res)?"true":"false"); } Label_exit: if (data1d) {delete []data1d; data1d=0;} //should never delete outimg here, as it is just a wrapper. by PHC 20131105 return b_res; }
bool GVFplugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("gvf_segmentation")) { int c=1; gvfsegPara segpara; // default values segpara.diffusionIteration = 5; segpara.fusionThreshold = 3; segpara.minRegion = 10; vector<char*> infiles, inparas, outfiles; if(input.size() >= 1) infiles = *((vector<char*> *)input.at(0).p); if(input.size() >= 2) { inparas = *((vector<char*> *)input.at(1).p); if(inparas.size() >= 1) c = atoi(inparas.at(0)); if(inparas.size() >= 2) segpara.diffusionIteration = atoi(inparas.at(1)); if(inparas.size() >= 3) segpara.fusionThreshold = atoi(inparas.at(2)); if(inparas.size() >= 4) segpara.minRegion = atoi(inparas.at(3)); if(output.size() >= 1) outfiles = *((vector<char*> *)output.at(0).p); } char * inimg_file = ((vector<char*> *)(input.at(0).p))->at(0); char * outimg_file = ((vector<char*> *)(output.at(0).p))->at(0); cout<<"channel choice "<<c<<endl; cout<<"diffusion Iterations "<<segpara.diffusionIteration<<endl; cout<<"fusion threshold "<<segpara.fusionThreshold<<endl; cout<<"minimum region size "<<segpara.minRegion<<endl; cout<<"inimg_file = "<<inimg_file<<endl; cout<<"outimg_file = "<<outimg_file<<endl; // check the input parameters for invalid choices: if ((segpara.diffusionIteration<1)||(segpara.fusionThreshold<1)||(segpara.minRegion)<0) { cout<< "* * * * * * * * * * * * * "<<endl; cout<< "*"<<endl; cout<< "INVALID parameter selection, type "<<endl; cout<<" vaa3d -x gvf_cellseg -f help "<<endl; cout<<"for more information"<<endl; cout<< "* * * * * * * * * * * * * "<<endl; cout<<""<<endl; return false; } V3DLONG in_sz[4]; int datatype; unsigned char * data1d = 0; if(!simple_loadimage_wrapper(callback, inimg_file, data1d, in_sz, datatype)) { cerr<<"load image "<<inimg_file<<" error!"<<endl; return false; } // allocate memory for the images Vol3DSimple <unsigned char> * tmp_inimg = 0; Vol3DSimple <USHORTINT16> * tmp_outimg = 0; try { tmp_inimg = new Vol3DSimple <unsigned char> (in_sz[0], in_sz[1], in_sz[2]); tmp_outimg = new Vol3DSimple <USHORTINT16> (in_sz[0], in_sz[1], in_sz[2]); } catch (...) { v3d_msg("Unable to allocate memory for processing."); if (tmp_inimg) {delete tmp_inimg; tmp_inimg=0;} if (tmp_outimg) {delete tmp_outimg; tmp_outimg=0;} return false; } //load image // Image4DSimple * temp4D = callback.loadImage(inimg_file); in_sz[0]=temp4D->getXDim(); in_sz[1]=temp4D->getYDim(); in_sz[2]=temp4D->getZDim(); in_sz[3]=temp4D->getCDim(); if (in_sz[3]==1) { c=1; cout<< "Image only has 1 channel, segmenting channel 1"<<endl; } if ((c>in_sz[3])||(c<1)) { cout<< "* * * * * * * * * * * * * "<<endl; cout<< "*"<<endl; cout<< "INVALID CHANNEL SELECTION: User selected channel "<<c<< "; image has "<< in_sz[3] << " channels."<<endl; cout<< " aborting segmentation !"<<endl; cout<<"*"<<endl; cout<< "* * * * * * * * * * * * * "<<endl; cout<<""<<endl; return false; } //transfer single channel of data from Image4DSimple to old Vol3DSimple class memcpy((void *)tmp_inimg->getData1dHandle(), (void *)temp4D->getRawDataAtChannel(c-1), in_sz[0]*in_sz[1]*in_sz[2]); //now do computation using external function call bool b_res = gvfCellSeg(tmp_inimg, tmp_outimg, segpara); // clear out temporary space if (tmp_inimg) {delete tmp_inimg; tmp_inimg=0;} // now write to file in_sz[3]=1;//for single channel output from gvfCellSeg simple_saveimage_wrapper(callback, outimg_file, (unsigned char *)tmp_outimg->getData1dHandle(), in_sz, 2); //the output of gvfCellSeg is in 16bit // clear out temporary space if (tmp_outimg) {delete tmp_outimg; tmp_outimg=0;} if (temp4D) {delete temp4D; temp4D=0;} cout<<"Finished GVF Segmentation"<<endl; } else if (func_name == tr("help")) { cout<<endl; cout<<endl; cout<<" GVF segmentation plugin usage : vaa3d -x gvf_cellseg -f gvf_segmentation -i <input filename> -o <output filename -p <c> <iter> <fusion> <size>"<<endl; cout<<" parameters: (default values in parentheses) "<<endl; cout<<"c = channel of input file to use for segmentation (1) "<<endl; cout<<"iter = number of diffusion iterations (must be > 0) (5) "<<endl; cout<<"fusion = fusion size threshold (must be > 0) (3) "<<endl; cout<<"size = minimum region size in voxels (10)"<<endl; } else return false; return true; }
bool compute(V3DPluginCallback2 &callback, const V3DPluginArgList & input, V3DPluginArgList & output) { cout<<"Welcome to histogram"<<endl; if(output.size() != 1) return true; vector<char*>* inlist = (vector<char*>*) (input.at(0).p); if (inlist->size() != 1) { cerr<<"You must specify 1 input file!"<<endl; return false; } char * infile = inlist->at(0); cout<<"input file: "<<infile<<endl; unsigned char * inimg1d = NULL; V3DLONG sz[4]; int datatype; if (!simple_loadimage_wrapper(callback, infile, inimg1d, sz, datatype)) { cerr<<"faile to load image"<<endl; return false; } //Read the output file vector<char*>* outlist = (vector<char*>*) (output.at(0).p); if (outlist->size()!=1) { cerr<<"You must specify 1 output file!"<<endl; return false; } char* outfile = outlist->at(0); cout<<"output file: "<<outfile<<endl; if (datatype!=1) { v3d_msg("Now we only support 8 bit image.\n"); return -1; } //TODO add datatype judgment double max_value = 256; V3DLONG histscale = 256; QVector<QVector<int> > hist_vec; int nChannel = sz[3]; for (int c=0;c<nChannel;c++) { QVector<int> tmp; getHistogram(inimg1d+ c*sz[0]*sz[1]*sz[2], sz[0]*sz[1]*sz[2], max_value, histscale, tmp); hist_vec.append(tmp); } //output histogram to csv file FILE *fp; fp = fopen(outfile, "w"); for (int i=0;i<hist_vec.size();i++) { for (int j=0;j<hist_vec[i].size();j++) fprintf(fp, "%d,", hist_vec[i][j]); fprintf(fp,"\n"); } fclose(fp); if (inimg1d) {delete []inimg1d; inimg1d=NULL;} return true; }
bool IBioformatIOPlugin::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("imgiobiof")) { cout<<"Welcome to imageIOBioformat loader"<<endl; if(input.size() != 1 || output.size() != 1) return false; char * inimg_file = ((vector<char*> *)(input.at(0).p))->at(0); char * outimg_file = ((vector<char*> *)(output.at(0).p))->at(0); cout<<"inimg_file = "<<inimg_file<<endl; cout<<"outimg_file = "<<outimg_file<<endl; QString m_FileName(inimg_file); // use inimge_file name if(m_FileName.isEmpty()) { printf("\nError: Your image does not exist!\n"); return false; } // temp QString baseName = QFileInfo(m_FileName).baseName(); //QString tmpfile = QDir::tempPath().append("/").append(baseName).append(".tif"); QString tmpfile(outimg_file); //use outimg_file name // QFile tmpqfile(tmpfile); if (tmpqfile.exists()) system(qPrintable(QString("rm -f \"%1\"").arg(tmpfile))); //look for loci_tools.jar QString lociDir = ("loci_tools.jar"); if (!QFile(lociDir).exists()) { printf("loci_tools.jar is not in current directory, search v3d app path.\n"); lociDir = getAppPath().append("/loci_tools.jar"); printf(qPrintable(lociDir)); printf("\n"); if (!QFile(lociDir).exists()) { v3d_msg("Cannot find loci_tools.jar, please download it and make sure it is put under the Vaa3D executable folder, parallel to the Vaa3D executable and the plugins folder.", 0); return false; } } QString cmd_loci = QString("java -cp %1 loci.formats.tools.ImageConverter \"%2\" \"%3\"").arg(lociDir.toStdString().c_str()).arg(m_FileName.toStdString().c_str()).arg(tmpfile.toStdString().c_str()); v3d_msg(cmd_loci, 0); system(qPrintable(cmd_loci)); if (!tmpqfile.exists()) { v3d_msg("The temprary file does not exist. The conversion of format using Bioformats has failed. Please use another way to convert and load using Vaa3D.\n"); return false; } return true; } else if(func_name == tr("help")) { cout<<"Usage : v3d -x imageIO_Bioformat -f imgiobiof -i <inimg_file> -o <outimg_file>"<<endl; cout<<"e.g. v3d -x imageIO_Bioformat -f imgiobiof -i input.raw -o output.raw"<<endl; cout<<endl; return true; } }
bool MovieConverter::dofunc(const QString & func_name, const V3DPluginArgList & input, V3DPluginArgList & output, V3DPluginCallback2 & callback, QWidget * parent) { if (func_name == tr("convert_frames_to_movie")) { cout<<"Welcome to movie converter"<<endl; char * inimg_file = ((vector<char*> *)(input.at(0).p))->at(0); QString check_ffmpeg; const char * ffmpeg_file; #if defined(Q_OS_MAC) ffmpeg_file = getAppPath().append("/mac_ffmpeg").toStdString().c_str(); #elif defined(Q_OS_LINUX) ffmpeg_file = getAppPath().append("/linux_ffmpeg").toStdString().c_str(); #elif defined(Q_OS_WIN32) ffmpeg_file = getAppPath().append("/linux_ffmpeg").toStdString().c_str(); #else v3d_msg("The OS is not recognized (not Mac, Linux or Windows). Do nothing."); return false; #endif char * inimg_format = "a[NUM].BMP"; char * output_fps = "14"; char * output_Type = "avi"; unsigned int c = 1; if (input.size()>=2) { vector<char*> paras = (*(vector<char*> *)(input.at(1).p)); cout<<paras.size()<<endl; if(paras.size() >= 1) check_ffmpeg = paras[0]; if(check_ffmpeg != "NULL") ffmpeg_file = paras[0] ; if(paras.size() >= 2) inimg_format = paras[1]; if(paras.size() >= 3) output_fps = paras[2]; if(paras.size() >= 4) output_Type = paras.at(3); if(paras.size() >= 5) c = atoi(paras.at(4)); } cout<<"input_folder = "<<inimg_file<<endl; cout<<"ffmpeg_file = "<<ffmpeg_file<<endl; cout<<"input_format = "<<inimg_format<<endl; cout<<"output_fps = "<<output_fps<<endl; cout<<"output_type = "<<output_Type<<endl; cout<<"compress = "<<c<<endl; QString selectedFile(inimg_file); QString selectffmpeg(ffmpeg_file); QString filename(inimg_format); QString fps(output_fps); QString videoType(output_Type); if (!QFile(selectffmpeg).exists()) { printf("Can not find ffmpeg, please select again or download from http://www.ffmpeg.org"); return false; } int indexL = filename.indexOf("["); QString filenameL = filename.left(indexL); int indexR = filename.indexOf("]"); QString filenameR = filename.right(filename.size()-indexR-1); QString compress; if(videoType == "mp4") { compress = "-vcodec mpeg4 -acodec aac"; } else if (videoType == "mpg") { compress = "-vcodec mpeg2video"; } else if (c == 1 && videoType == "avi") { compress = "-vcodec mjpeg -qscale 0"; } else if (c == 0 && videoType == "avi") { compress = "-vcodec rawvideo"; } else { return false; } #if defined(Q_OS_WIN32) QString cmd_ffmpeg = QString("\"\"%1\" -r %2 -i \"%3/%4%d%5\" -y %6 \"%7/movie.%8\"\"").arg(selectffmpeg.toStdString().c_str()).arg(fps.toStdString().c_str()).arg(selectedFile.toStdString().c_str()).arg(filenameL.toStdString().c_str()).arg(filenameR.toStdString().c_str()).arg(compress.toStdString().c_str()).arg(selectedFile.toStdString().c_str()).arg(videoType.toStdString().c_str()); #else QString cmd_ffmpeg = QString("\"%1\" -r %2 -i \"%3/%4%d%5\" -y %6 \"%7/movie.%8\"").arg(selectffmpeg.toStdString().c_str()).arg(fps.toStdString().c_str()).arg(selectedFile.toStdString().c_str()).arg(filenameL.toStdString().c_str()).arg(filenameR.toStdString().c_str()).arg(compress.toStdString().c_str()).arg(selectedFile.toStdString().c_str()).arg(videoType.toStdString().c_str()); #endif system(qPrintable(cmd_ffmpeg)); //-vcodec mjpeg -qscale 0 QString movieDir = selectedFile.append(QString("/movie.%1").arg(videoType)); if (!QFile(movieDir).exists()) { printf("The format is not supported, or can not find ffmpeg, please select again or download from http://www.ffmpeg.org\n"); return false; } else { cout<<"The movie is saved in "<<movieDir.toStdString()<<endl; return true; } } else if (func_name == tr("help")) { printf("\n**** Usage of Movie Converter ****\n"); printf("vaa3d -x plugin_name -f convert_frames_to_movie -i <inimg_folder> -p <converter_path> <frame_format> <output_fps> <video_type> <is_compress>\n"); printf("inimg_folder the video frame folder path \n"); printf("converter_path the movie converter(ffmpeg) path. If do not know, please set this para to NULL and the default path will be the vaa3d main path.\n"); printf("frame_format the format of video frames,e.g. for a1.BMP, please set this para to be a[NUM].BMP\n"); printf("output_fps the fps for the output video. Default 14\n"); printf("video_type the output video type (avi, mpg, or mp4). Default avi.\n"); printf("is_compress if compress the video (1 for yes and 0 for no). Default 1.\n"); return true; } else return false; }