コード例 #1
0
ファイル: asciitf2vtf.cpp プロジェクト: yyr/vapor
int	main(int argc, char **argv) {

	OptionParser op;

	ProgName = Basename(argv[0]);

	if (op.AppendOptions(set_opts) < 0) {
		cerr << ProgName << " : " << op.GetErrMsg();
		exit(1);
	}

	if (op.ParseOptions(&argc, argv, get_options) < 0) {
		cerr << ProgName << " : " << OptionParser::GetErrMsg();
		exit(1);
	}

	MyBase::SetErrMsgCB(ErrMsgCBHandler);

	if (opt.help) {
		Usage(op, NULL);
		exit(0);
	}

	if (argc != 2) {
		Usage(op, "Wrong number of arguments");
		exit(1);
	}
	
	if ((strlen(opt.cmap) == 0) && (strlen(opt.omap) == 0)) {
		Usage(op, "Wrong number of arguments");
		exit(1);
	}

	TransferFunctionLite tf(8);
	if (MyBase::GetErrCode() !=0) exit(1);

	tf.setMinColorMapValue(0.0);
	tf.setMaxColorMapValue(1.0);
	tf.setMinOpacMapValue(0.0);
	tf.setMaxOpacMapValue(1.0);

	string vtffile(argv[1]);

	int rc;

	if (strlen(opt.cmap) != 0) {
		ProcessCMAP(&tf, opt.type);
	}

	if (strlen(opt.omap) != 0) {
		float point, o;
		vector <float> pvec, ovec;

		OpacityMapBase *omap = tf.getOpacityMap(0);
		omap->clear();

		FILE *fp = fopen(opt.omap, "r");
		if (! fp) {
			MyBase::SetErrMsg("fopen(%s) : %M", opt.omap);
			exit(1);
		}

		const char *format = "%f %f";

		while ((rc = fscanf(fp, format, &point, &o)) == 2) { 
			pvec.push_back(point);
			ovec.push_back(o);
		}

		vector <float> tmpvec = pvec;
		sort(tmpvec.begin(), tmpvec.end());
		tf.setMinOpacMapValue(tmpvec[0]);
		tf.setMaxOpacMapValue(tmpvec[tmpvec.size()-1]);
		omap->minValue(tmpvec[0]);
		omap->maxValue(tmpvec[tmpvec.size()-1]);

		for (int i=0; i<pvec.size(); i++) {
//			omap->addNormControlPoint(pvec[i],  ovec[i]);
			omap->addControlPoint(pvec[i],  ovec[i]);
		}
		omap->minValue(0.0);
		omap->maxValue(1.0);

		if (ferror(fp)) {
			MyBase::SetErrMsg("Error parsing file %s", opt.omap);
			exit(1);
		}
		fclose(fp);
	} // End of if omap.

	//
	// Write output file.
	//
	
	ofstream fileout;
	fileout.open(vtffile.c_str());
	if (! fileout) {
		MyBase::SetErrMsg(
			"Can't open file \"%s\" for writing", vtffile.c_str()
		);
		exit(1);
	} 
	if (! (tf.saveToFile(fileout)))
		exit(1);

	exit(0);
} // End of Main.
コード例 #2
0
ファイル: raw2vdf.cpp プロジェクト: yyr/vapor
int	main(int argc, char **argv) {

	OptionParser op;
	FILE	*fp;
	const char	*metafile;
	const char	*datafile;

	float	timer = 0.0;
	float	read_timer = 0.0;
	float	write_timer = 0.0;
	float	xform_timer = 0.0;
	string	s;

	MyBase::SetErrMsgCB(ErrMsgCBHandler);

	//
	// Parse command line arguments
	//
	ProgName = Basename(argv[0]);

	if (op.AppendOptions(set_opts) < 0) {
		exit(1);
	}

	if (op.ParseOptions(&argc, argv, get_options) < 0) {
		exit(1);
	}

	if (opt.help) {
		cerr << "Usage: " << ProgName << " [options] vdfFile outputFile" << endl;
		op.PrintOptionHelp(stderr);
		exit(0);
	}

	if (argc != 3) {
		cerr << "Usage: " << ProgName << " [options] vdfFile dataFile" << endl;
		op.PrintOptionHelp(stderr);
		exit(1);
	}

	metafile = argv[1];	// Path to a vdf file
	datafile = argv[2];	// Path to raw data file 

    if (opt.debug) MyBase::SetDiagMsgFilePtr(stderr);

	WaveletBlockIOBase	*wbwriter3D = NULL;
	WaveCodecIO	*wcwriter = NULL;
	VDFIOBase *vdfio = NULL;

	size_t min[3] = {opt.xregion.min, opt.yregion.min, opt.zregion.min};
	size_t max[3] = {opt.xregion.max, opt.yregion.max, opt.zregion.max};

	// Determine if variable is 3D
	//
	MetadataVDC metadata (metafile);
	if (MetadataVDC::GetErrCode() != 0) {
		MyBase::SetErrMsg("Error processing metafile \"%s\"", metafile);
		exit(1);
	}
	Metadata::VarType_T vtype = metadata.GetVarType(opt.varname);
	if (vtype == Metadata::VARUNKNOWN) {
		MyBase::SetErrMsg("Unknown variable \"%s\"", opt.varname);
		exit(1);
	}

	
	bool vdc1 = (metadata.GetVDCType() == 1);
	if (vdc1) {

		// Create an appropriate WaveletBlock writer. 
		//
		if (min[0] == min[1] && min[1] == min[2] && min[2] == max[0] &&
			max[0] == max[1]  && max[1] == max[2] && max[2] == (size_t) -1 &&
			vtype == Metadata::VAR3D) {

			wbwriter3D = new WaveletBlock3DBufWriter(metadata);
		}
		else {
			wbwriter3D = new WaveletBlock3DRegionWriter(metadata);
		}
		vdfio = wbwriter3D;
	} 
	else {
		wcwriter = new WaveCodecIO(metadata, opt.nthreads);
		vdfio = wcwriter;
	}
	if (vdfio->GetErrCode() != 0) {
		exit(1);
	}

	fp = FOPEN64(datafile, "rb");
	if (! fp) {
		MyBase::SetErrMsg("Could not open file \"%s\" : %M", datafile);
		exit(1);
	}


	double t0 = GetTime();

	if (min[0] == min[1] && min[1] == min[2] && min[2] == max[0] &&
		max[0] == max[1]  && max[1] == max[2] && max[2] == (size_t) -1 &&
		vtype == Metadata::VAR3D) {

		process_volume(
			vdfio, fp, vtype, &read_timer,
			&write_timer, &xform_timer
		);
	}
	else {
		process_region(
			vdfio, fp, vtype, 
			&read_timer, &write_timer, &xform_timer
		);
	}


	timer = GetTime() - t0;

	if (! opt.quiet) {
		const float *range = vdfio->GetDataRange();

		fprintf(stdout, "read time : %f\n", read_timer);
		fprintf(stdout, "write time : %f\n", write_timer);
		fprintf(stdout, "transform time : %f\n", xform_timer);
		fprintf(stdout, "total transform time : %f\n", timer);
		fprintf(stdout, "min and max values of data output: %g, %g\n",range[0], range[1]);
	}

	exit(0);
}
コード例 #3
0
ファイル: vdfls.cpp プロジェクト: yyr/vapor
int	main(int argc, char **argv) {

	OptionParser op;
	const char	*metafile;

	string	s;

	MyBase::SetErrMsgCB(ErrMsgCB);

	ProgName = Basename(argv[0]);

	if (op.AppendOptions(set_opts) < 0) {
		cerr << ProgName << " : " << op.GetErrMsg();
		exit(1);
	}

	if (op.ParseOptions(&argc, argv, get_options) < 0) {
		cerr << ProgName << " : " << op.GetErrMsg();
		exit(1);
	}

	if (opt.help) {
		cerr << "Usage: " << ProgName << " [options] metafile datafile" << endl;
		op.PrintOptionHelp(stderr);
		exit(0);
	}

	if (argc != 2) {
		cerr << "Usage: " << ProgName << " [options] metafile " << endl;
		op.PrintOptionHelp(stderr);
		exit(1);
	}

	metafile = argv[1];
	map <long, map <string, VarFileInfo > > statsvec;


	const MetadataVDC *metadata = new MetadataVDC(metafile);
	if (MyBase::GetErrCode() != 0) exit(1);

	if (getStats(metadata, statsvec) < 0) {
		exit(1);
	}
	

	string sort = opt.sort;

	int numApproximations;
	if (metadata->GetVDCType() == 2) {
		if (opt.level < 0) numApproximations = metadata->GetCRatios().size();
		else numApproximations = opt.level+1;
	} else {
		if (opt.level < 0) numApproximations = metadata->GetNumTransforms()+1;
		else numApproximations = opt.level+1;
	}

	if (sort.compare("time") == 0) {
		map <long, map <string, VarFileInfo > >::iterator iter1;
		for (iter1 = statsvec.begin(); iter1 != statsvec.end(); iter1++) {
			map <string, VarFileInfo>::iterator iter2;

			for (iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++) {
				const VarFileInfo &vfiref = iter2->second;

				for(int j=0; j<numApproximations; j++) {
					PrintVariable(metadata,vfiref, j);
				}
			}
		}
	}
	else if (sort.compare("level") == 0) {
		for (int j=0; j<numApproximations; j++) {
			map <long, map <string, VarFileInfo > >::iterator iter1;
			for (iter1 = statsvec.begin(); iter1 != statsvec.end(); iter1++) {
				map <string, VarFileInfo>::iterator iter2;

				for (iter2 = iter1->second.begin(); iter2 != iter1->second.end(); iter2++) {
					const VarFileInfo &vfiref = iter2->second;

					PrintVariable(metadata,vfiref, j);
				}
			}
		}
	}
	else if (sort.compare("varname") == 0) {
		const vector <string> varNames = metadata->GetVariableNames();
		vector <string>::const_iterator iter1;
		for (iter1=varNames.begin(); iter1 != varNames.end(); iter1++) {
		
			for (int j=0; j<numApproximations; j++) {
				map <long, map <string, VarFileInfo > >::iterator iter2;
				for (iter2 = statsvec.begin(); iter2 != statsvec.end(); iter2++) {

					const VarFileInfo &vfiref = iter2->second[*iter1];;

					PrintVariable(metadata,vfiref, j);
				}
			}
		}
	}
	else {
		MyBase::SetErrMsg("Invalid sort \"%s\"", sort.c_str());
		exit(1);
	}

	exit(0);
}