예제 #1
0
void BackGround::GetBackground_One_pass( string srcfilename,string outputdir,unsigned int width,unsigned int height, cv::Size win_stride)
{
	Init(width,height);
	LoadPictures(srcfilename);
	SetOutputDir(outputdir);

	string filepath;
	ifstream fin(m_srcfilename.c_str(),ios_base::in);
	if(!fin.is_open())
	{
#ifdef DEBUG_OUTPUT
		cout<<"Open File Error"<<endl;
#endif
		exit(1);
	}
	cv::Mat tmpimg;
	while(getline(fin,filepath))
	{
		m_input.release();
		tmpimg=cv::imread(filepath,0);
		cv::copyMakeBorder(tmpimg,m_input,40,40,40,40,cv::BORDER_REPLICATE);
		SetPrefix(GetFileName(filepath.c_str()));
		OutputBackground_OnePass(win_stride);
	}
	fin.close();
}
예제 #2
0
void BackGround::InitOutputPerBackground(string srcfilename,string outputdir,unsigned int width,unsigned int height,double scale,double scalefactor,double step)
{
	Init(width,height);
	LoadPictures(srcfilename);
	SetOutputDir(outputdir);

	m_fin.open(m_srcfilename.c_str(),ios_base::in);
	if(!m_fin.is_open())
	{
#ifdef DEBUG_OUTPUT
		cout<<"Open File Error"<<endl;
#endif
		exit(1);
	}

	m_currentroi.width=m_bgroi.width;
	m_currentroi.height=m_bgroi.height;

	m_scale=scale;
	m_scalefactor=scalefactor;
	m_step=step;
}
예제 #3
0
void BackGround::GetBackground(string srcfilename,string outputdir,unsigned int width,unsigned int height,double scale,double scalefactor,double step)
{
	Init(width,height);
	LoadPictures(srcfilename);
	SetOutputDir(outputdir);

	string filepath;
	ifstream fin(m_srcfilename.c_str(),ios_base::in);
	if(!fin.is_open())
	{
#ifdef DEBUG_OUTPUT
		cout<<"Open File Error"<<endl;
#endif
		exit(1);
	}
	while(getline(fin,filepath))
	{
		m_input.release();
		m_input=cv::imread(filepath,0);
		SetPrefix(GetFileName(filepath.c_str()));
		OutputBackground(scale,scalefactor,step);
	}
	fin.close();
}
// Radomized trials for registering a point cloud and mesh
//  sample noise is dependent on surface normal orientation
//  (assumes mesh itself has no measurement noise)
void Run_ParameterizedTest_Mesh_SurfaceNoise(TestParameters params)
{
  std::stringstream ss;

  std::string loadSourceMeshPath = params.inputDir + "/" + params.sourceMeshFile;
  std::string loadTargetMeshPath = params.inputDir + "/" + params.targetMeshFile;
  std::string saveSourceMeshPath = params.outputCommonDir + "/SaveMeshSource";
  std::string saveTargetMeshPath = params.outputCommonDir + "/SaveMeshTarget";
  std::string saveNoisyTargetMeshPath = params.outputCommonDir + "/SaveMeshTargetNoisy";
  std::string saveTargetCov = params.outputCommonDir + "/SaveTargetCov.txt";

  // test parameters
  params.GenerateSamplesFunc = GenerateSamplePointSet_PointCloud_SurfaceNoise;
  CustomTestParams_PointCloud_SurfaceNoise &customParams
    = dynamic_cast<CustomTestParams_PointCloud_SurfaceNoise&> (*params.pCustomTestParams);

  // load target mesh
  cisstMesh mesh_target;
  CreateMesh(mesh_target, loadTargetMeshPath, &saveTargetMeshPath);

  // load source mesh
  //  NOTE: the sample point set is randomly generated from this mesh
  cisstMesh mesh_source;
  CreateMesh(mesh_source, loadSourceMeshPath, &saveSourceMeshPath);

  // generate noisy target mesh
  //  NOTE: the sample point set is registered to this mesh
  cisstMesh noisyTargetMesh;
  if (params.noiseMeshSD != 0.0)
  {
    std::cout << "ERROR: noisy mesh currently disabled" << std::endl;
    return;
    //std::string normRVFile = params.inputDir + "/GaussianValues.txt";
    //std::ifstream randnStream_MeshNoise(normRVFile.c_str());
    //GenerateNoisyMesh(mesh_target, noisyTargetMesh, randnStream_MeshNoise, params.noiseMeshSD, &saveNoisyTargetMeshPath);
  }
  else
  {
    noisyTargetMesh = mesh_target;
  }

  // build mesh covariance tree from noisy mesh
  cisstCovTree_Mesh   *pTree;
  int    nThresh = 5;       // Cov Tree Params
  double diagThresh = 5.0;  //  ''
  std::cout << "Building covariance tree .... " << std::endl;
  pTree = new cisstCovTree_Mesh(noisyTargetMesh, nThresh, diagThresh);
  std::cout << "Tree built: NNodes=" << pTree->NumNodes() << " NData=" << pTree->NumData()
    << " TreeDepth=" << pTree->TreeDepth() << std::endl;
  assert(pTree->NumNodes());

  // Apply target noise model
  if (customParams.bTargetCov_ApplySurfaceModel)
  {
    // define mesh noise model (surface-model)
    noisyTargetMesh.ComputeTriangleNoiseModels(
      customParams.surfaceModel_InPlaneSD,
      customParams.surfaceModel_PerpPlaneSD);

    // save target covariance model
    noisyTargetMesh.SaveTriangleCovariances(saveTargetCov);
  }


  // ICP Options
  cisstICP::Options opt_ICP;
  opt_ICP.auxOutputDir = params.outputBaseDir + "/AuxiliaryFiles/";
  opt_ICP.maxIter = 100;
  opt_ICP.termHoldIter = 2;
  opt_ICP.minE = -std::numeric_limits<double>::max();
  opt_ICP.tolE = 0.0;
  opt_ICP.dPosThresh = 0.1;
  opt_ICP.dAngThresh = 0.1*(cmnPI / 180);
  opt_ICP.dPosTerm = 0.001;
  opt_ICP.dAngTerm = 0.001*(cmnPI / 180);
  params.opt_ICP = opt_ICP;

#define nNoises     9
#define nOffsets    2
#define nTests      (nNoises*nOffsets)
  //#define nOutliers   6
  //#define nTests      (nNoises*nOffsets*nOutliers)
  //double percentOutliers[nOutliers] = { 0.05, 0.1, 0.2, 0.3, 0.4, 0.5 };

  double noiseInPlaneSDArr[nNoises] = { 0.5, 1.0, 2.0, 0.5, 1.0, 0.5, 1.0, 2.0, 2.0 };
  double noisePerpPlaneSDArr[nNoises] = { 0.5, 1.0, 2.0, 1.0, 2.0, 2.0, 0.5, 1.0, 0.5 };
  //double noiseInPlaneSDArr[nNoises] = { 0.5, 1.0 };
  //double noisePerpPlaneSDArr[nNoises] = { 0.5, 1.0 };

  double minOffsetAngArr[nOffsets] = { 30, 15 }; //{ 10, 30 }; //{0,  10, 30, 60};
  double maxOffsetAngArr[nOffsets] = { 60, 30 }; //{ 30, 60 }; //{10, 30, 60, 90};
  double minOffsetPosArr[nOffsets] = { 30, 15 }; //{ 10, 30 }; //{0,  10, 30, 60};
  double maxOffsetPosArr[nOffsets] = { 60, 30 }; //{ 30, 60 }; //{10, 30, 60, 100};

  std::vector<unsigned int> randSeed_SamplesArr(nTests, 0);   // sample generater
  std::vector<unsigned int> randSeed_XfmsArr(nTests, 0);     // initial offset xfm generater

  for (unsigned int i = 0; i < nTests; i++)
  {
    randSeed_SamplesArr[i] = i + 23;
    randSeed_XfmsArr[i] = i + 127;
  }

  std::string outputCommonDir = params.outputCommonDir;
  params.nSamples = customParams.nGoodSamples;

  //--- Parameterized Trials ---//

  for (unsigned int offset = 0; offset < nOffsets; offset++)
  {
    for (unsigned int noise = 0; noise < nNoises; noise++)
    {
      unsigned int testNum = offset*nNoises + noise;

      ss.str("");
      ss << "Noise_Prll" << noiseInPlaneSDArr[noise] << "Perp" << noisePerpPlaneSDArr[noise]
        << "_Offset_R" << minOffsetAngArr[offset] << "-" << maxOffsetAngArr[offset]
        << "T" << minOffsetPosArr[offset] << "-" << maxOffsetPosArr[offset];
      //<< "_Outliers" << percentOutliers[outlier];
      std::string outputSubFolder = ss.str();

      params.minOffsetAng = minOffsetAngArr[offset];
      params.maxOffsetAng = maxOffsetAngArr[offset];
      params.minOffsetPos = minOffsetPosArr[offset];
      params.maxOffsetPos = maxOffsetPosArr[offset];
      params.randSeed_Samples = randSeed_SamplesArr[testNum];
      params.randSeed_Xfms = randSeed_XfmsArr[testNum];

      customParams.sampleNoise_InPlaneSD = noiseInPlaneSDArr[noise];
      customParams.sampleNoise_PerpPlaneSD = noisePerpPlaneSDArr[noise];

      // hold number of good samples constant and increase sample size to
      //  achieve the desired percentage of outliers
      //double p = percentOutliers[outlier];
      //unsigned int nOutlierSamps = (unsigned int)(p/(1-p) * customParams.nGoodSamples);
      //params.nSamples = customParams.nGoodSamples + nOutlierSamps;      


      // TODO: remove change to output common files to separate directories below

      // Run StdICP
      {
        params.AlgorithmDescription = "StdICP";
        //params.AlgorithmDescription = "StdICP_Verbose";
        params.algType = TestParameters::StdICP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        params.pAlg = new cisstAlgorithmICP_StdICP_Mesh(pTree, dummySamples);
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

      // Run IMLP
      {
        params.AlgorithmDescription = "IMLP";
        //params.AlgorithmDescription = "IMLP_Verbose";
        params.algType = TestParameters::IMLP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        vctDynamicVector<vct3x3> dummySampleCov;  //  ''
        cisstAlgorithmICP_IMLP_Mesh *pAlg =
          new cisstAlgorithmICP_IMLP_Mesh(
          pTree, dummySamples, dummySampleCov, dummySampleCov, customParams.outlier_ChiSquareThreshold);          
        params.pAlg = pAlg;
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

      // Run IMLP_MD (Mahalanobis Distance Match Criteria)
      {
        params.AlgorithmDescription = "IMLP-MD";
        //params.AlgorithmDescription = "IMLP-MD_Verbose";
        params.algType = TestParameters::IMLP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        vctDynamicVector<vct3x3> dummySampleCov;  //  ''
        cisstAlgorithmICP_IMLP_MahalDist_Mesh *pAlg =
          new cisstAlgorithmICP_IMLP_MahalDist_Mesh(
          pTree, dummySamples, dummySampleCov, dummySampleCov, customParams.outlier_ChiSquareThreshold);
        params.pAlg = pAlg;
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

      // Run IMLP_CP (Closest Point Match Criteria)
      {
        params.AlgorithmDescription = "IMLP-CP";
        //params.AlgorithmDescription = "IMLP-CP_Verbose";
        params.algType = TestParameters::IMLP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        vctDynamicVector<vct3x3> dummySampleCov;  //  ''
        cisstAlgorithmICP_IMLP_ClosestPoint_Mesh *pAlg =
          new cisstAlgorithmICP_IMLP_ClosestPoint_Mesh(
          pTree, dummySamples, dummySampleCov, dummySampleCov, customParams.outlier_ChiSquareThreshold);
        params.pAlg = pAlg;
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

    }
  }
}
// Radomized trials for registering 2 point clouds
//  sample noise is dependent on surface normal orientation
//  (assumes mesh itself has no measurement noise)
void Run_ParameterizedTest_PointCloud_SurfaceNoise(TestParameters params)
{
  std::stringstream ss;

  //std::string workingDir = "../ICP_TestData";
  //std::string baseOutputFolder = "RandomTestData_PointCloud_SurfaceNoise";  // "RandomTests_Plane2Plane_Term0.001G_5.0,0.5_ChiSqu0.95_A0_Sigma2/";
  //std::string sourceMeshFile = "RIGHTHEMIPELVIS_centered.mesh";
  //std::string targetMeshFile = sourceMeshFile;

  //// Create folders for output files
  //std::string baseOutputDir = workingDir + "/" + baseOutputFolder;
  //std::string commonOutputDir = baseOutputDir + "/CommonFiles";
  //CreateDir(baseOutputDir);
  //CreateDir(commonOutputDir);

  std::string loadSourceMeshPath = params.inputDir + "/" + params.sourceMeshFile;
  std::string loadTargetMeshPath = params.inputDir + "/" + params.targetMeshFile;
  std::string saveSourceMeshPath = params.outputCommonDir + "/SaveMeshSource";
  std::string saveTargetMeshPath = params.outputCommonDir + "/SaveMeshTarget";
  std::string saveNoisyTargetMeshPath = params.outputCommonDir + "/SaveMeshTargetNoisy";

  //// test parameters
  //TestParameters params;
  //params.TestDescription = "Run_ParameterizedTest_PointCloud_SurfaceNoise";
  //params.inputDir = workingDir;
  //params.sourceMeshFile = sourceMeshFile;
  //params.targetMeshFile = targetMeshFile;
  //params.numTrials = 2; // 300;
  //params.nSamples = 100;
  //params.nValidationSamples = 100;
  //params.noiseMeshSD = 0.0;
  //params.randSeed_MeshNoise = 0;
  params.GenerateSamplesFunc = GenerateSamplePointSet_PointCloud_SurfaceNoise;
  CustomTestParams_PointCloud_SurfaceNoise &customParams
    = dynamic_cast<CustomTestParams_PointCloud_SurfaceNoise&> (*params.pCustomTestParams);

  //// custom test parameters
  //// NOTE: target point cloud noise model
  ////        perpendicular noise must be specified
  ////        in-plane noise is set to avg distance from triangle center to each vertex
  //CustomTestParams_PointCloud_SurfaceNoise customParams;
  //params.pCustomTestParams = &customParams;
  //customParams.percentOutliers = 0.0;
  //customParams.bSampleCov_ApplyNoiseModel = true;
  //customParams.bSampleCov_ApplySurfaceModel = true;
  //customParams.bTargetCov_ApplySurfaceModel = true;
  //customParams.bTargetCov_DynamicSurfaceModel = false;
  //customParams.surfaceModel_InPlaneSD = 5.0;
  //customParams.surfaceModel_PerpPlaneSD = 0.5;
  //customParams.minPosOffsetOutlier = 10.0;
  //customParams.maxPosOffsetOutlier = 20.0;

  // load target mesh
  cisstMesh mesh_target;
  CreateMesh(mesh_target, loadTargetMeshPath, &saveTargetMeshPath);

  // load source mesh
  //  NOTE: the sample point set is randomly generated from this mesh
  cisstMesh mesh_source;
  CreateMesh(mesh_source, loadSourceMeshPath, &saveSourceMeshPath);

  // generate noisy target mesh
  //  NOTE: the sample point set is registered to this mesh
  cisstMesh noisyTargetMesh;
  if (params.noiseMeshSD > 0.0)
  {
    std::cout << "ERROR: noisy mesh currently disabled" << std::endl;
    return;
    //std::string normRVFile = params.inputDir + "/GaussianValues.txt";
    //std::ifstream randnStream_MeshNoise(normRVFile.c_str());
    //GenerateNoisyMesh(mesh_target, noisyTargetMesh, randnStream_MeshNoise, params.noiseMeshSD, &saveNoisyTargetMeshPath);
  }
  else
  {
    noisyTargetMesh = mesh_target;
  }

  // build point cloud covariance tree from noisy mesh
  //  and define point cloud noise model (but don't add more noise)
  cisstCovTree_PointCloud   *pTree;
  int    nThresh = 5;       // Cov Tree Params
  double diagThresh = 5.0;  //  ''
  std::cout << "Building covariance tree .... " << std::endl;
  double targetModel_InPlaneSD = params.noiseMeshSD;
  double targetModel_PerpPlaneSD = params.noiseMeshSD;
  if (customParams.bTargetCov_ApplySurfaceModel)
  {
    targetModel_InPlaneSD += customParams.surfaceModel_InPlaneSD;
    targetModel_PerpPlaneSD += customParams.surfaceModel_PerpPlaneSD;
  }
  if (customParams.bTargetCov_DynamicSurfaceModel && customParams.bTargetCov_ApplySurfaceModel)
  {
    // set target surface noise model dynamically from mesh
    pTree = new cisstCovTree_PointCloud(noisyTargetMesh, nThresh, diagThresh, targetModel_PerpPlaneSD);
    std::cout << "Tree built: NNodes=" << pTree->NumNodes() << " NData=" << pTree->NumData()
      << " TreeDepth=" << pTree->TreeDepth() << std::endl;
    std::cout << " Point Cloud Noise Model:" << std::endl
      << "  perp-plane variance = " << pow(customParams.surfaceModel_PerpPlaneSD, 2) << std::endl
      << "  in-plane variance = " << pTree->avgVarInPlane << " (avg)" << std::endl;
    assert(pTree->NumNodes());
  }
  else
  {
    // set static target surface noise model
    pTree = new cisstCovTree_PointCloud(noisyTargetMesh, nThresh, diagThresh, targetModel_PerpPlaneSD, targetModel_InPlaneSD);
    std::cout << "Tree built: NNodes=" << pTree->NumNodes() << " NData=" << pTree->NumData()
      << " TreeDepth=" << pTree->TreeDepth() << std::endl;
    std::cout << " Point Cloud Noise Model:" << std::endl
      << "  perp-plane variance = " << pow(customParams.surfaceModel_PerpPlaneSD, 2) << std::endl
      << "  in-plane variance = " << pow(customParams.surfaceModel_InPlaneSD, 2) << std::endl;
    assert(pTree->NumNodes());
  }
  // save target point cloud and covariance model
  std::string saveTargetPointCloud = params.outputCommonDir + "/SaveTargetPointCloud.pts";
  std::string saveTargetCov = params.outputCommonDir + "/SaveTargetCov.txt";
  pTree->SavePointCloud(saveTargetPointCloud);
  pTree->SavePointCloudCov(saveTargetCov);

  // ICP Options
  cisstICP::Options opt_ICP;
  opt_ICP.auxOutputDir = params.outputBaseDir + "/AuxiliaryFiles/";
  opt_ICP.maxIter = 100;
  opt_ICP.termHoldIter = 2;
  opt_ICP.minE = -std::numeric_limits<double>::max();
  opt_ICP.tolE = 0.0;
  opt_ICP.dPosThresh = 0.1;
  opt_ICP.dAngThresh = 0.1*(cmnPI / 180);
  opt_ICP.dPosTerm = 0.001;
  opt_ICP.dAngTerm = 0.001*(cmnPI / 180);
  params.opt_ICP = opt_ICP;

  //// CPD Options
  //CPD::Options opt_CPD;
  //opt_CPD.maxIter = opt_ICP.maxIter;
  //opt_CPD.termHoldIter = opt_ICP.termHoldIter;
  //opt_CPD.minE = opt_ICP.minE;
  //opt_CPD.tolE = opt_ICP.tolE;
  //opt_CPD.dPosThresh = opt_ICP.dPosThresh;
  //opt_CPD.dAngThresh = opt_ICP.dAngThresh;
  //opt_CPD.dPosTerm = opt_ICP.dPosTerm;
  //opt_CPD.dAngTerm = opt_ICP.dAngTerm;
  //opt_CPD.w = customParams.w;
  //params.opt_CPD = opt_CPD;

#define nNoises     9
#define nOffsets    2
#define nTests      (nNoises*nOffsets)
  //#define nOutliers   6
  //#define nTests      (nNoises*nOffsets*nOutliers)
  //double percentOutliers[nOutliers] = { 0.05, 0.1, 0.2, 0.3, 0.4, 0.5 };

  double noiseInPlaneSDArr[nNoises] = { 0.5, 1.0, 2.0, 0.5, 1.0, 0.5, 1.0, 2.0, 2.0 };
  double noisePerpPlaneSDArr[nNoises] = { 0.5, 1.0, 2.0, 1.0, 2.0, 2.0, 0.5, 1.0, 0.5 };
  //double noiseInPlaneSDArr[nNoises] = { 0.5, 1.0 };
  //double noisePerpPlaneSDArr[nNoises] = { 0.5, 1.0 };

  double minOffsetAngArr[nOffsets] = { 30, 15 }; //{ 10, 30 }; //{0,  10, 30, 60};
  double maxOffsetAngArr[nOffsets] = { 60, 30 }; //{ 30, 60 }; //{10, 30, 60, 90};
  double minOffsetPosArr[nOffsets] = { 30, 15 }; //{ 10, 30 }; //{0,  10, 30, 60};
  double maxOffsetPosArr[nOffsets] = { 60, 30 }; //{ 30, 60 }; //{10, 30, 60, 100};

  std::vector<unsigned int> randSeed_SamplesArr(nTests, 0);   // sample generater
  std::vector<unsigned int> randSeed_XfmsArr(nTests, 0);     // initial offset xfm generater

  for (unsigned int i = 0; i < nTests; i++)
  {
    randSeed_SamplesArr[i] = i + 23;
    randSeed_XfmsArr[i] = i + 127;
  }

  std::string outputCommonDir = params.outputCommonDir;
  params.nSamples = customParams.nGoodSamples;

  //--- Parameterized Trials ---//

  for (unsigned int offset = 0; offset < nOffsets; offset++)
  {
    for (unsigned int noise = 0; noise < nNoises; noise++)
    {
      unsigned int testNum = offset*nNoises + noise;

      ss.str("");
      ss << "Noise_Prll" << noiseInPlaneSDArr[noise] << "Perp" << noisePerpPlaneSDArr[noise]
        << "_Offset_R" << minOffsetAngArr[offset] << "-" << maxOffsetAngArr[offset]
        << "T" << minOffsetPosArr[offset] << "-" << maxOffsetPosArr[offset];
      //<< "_Outliers" << percentOutliers[outlier];
      std::string outputSubFolder = ss.str();

      params.minOffsetAng = minOffsetAngArr[offset];
      params.maxOffsetAng = maxOffsetAngArr[offset];
      params.minOffsetPos = minOffsetPosArr[offset];
      params.maxOffsetPos = maxOffsetPosArr[offset];
      params.randSeed_Samples = randSeed_SamplesArr[testNum];
      params.randSeed_Xfms = randSeed_XfmsArr[testNum];

      customParams.sampleNoise_InPlaneSD = noiseInPlaneSDArr[noise];
      customParams.sampleNoise_PerpPlaneSD = noisePerpPlaneSDArr[noise];

      // hold number of good samples constant and increase sample size to
      //  achieve the desired percentage of outliers
      //double p = percentOutliers[outlier];
      //unsigned int nOutlierSamps = (unsigned int)(p/(1-p) * customParams.nGoodSamples);
      //params.nSamples = customParams.nGoodSamples + nOutlierSamps;      


      // TODO: remove change to output common files to separate directories below

      // Run StdICP
      {
        params.AlgorithmDescription = "StdICP";
        //params.AlgorithmDescription = "StdICP_Verbose";
        params.algType = TestParameters::StdICP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        params.pAlg = new cisstAlgorithmICP_StdICP_PointCloud(pTree, dummySamples);
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

      // Run IMLP
      {
        params.AlgorithmDescription = "IMLP";
        //params.AlgorithmDescription = "IMLP_Verbose";
        params.algType = TestParameters::IMLP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        vctDynamicVector<vct3x3> dummySampleCov;  //  ''
        cisstAlgorithmICP_IMLP_PointCloud *pAlg =
          new cisstAlgorithmICP_IMLP_PointCloud(
          pTree, dummySamples, dummySampleCov, dummySampleCov, customParams.outlier_ChiSquareThreshold);          
        params.pAlg = pAlg;
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

      // Run IMLP_MD (Mahalanobis Distance Match Criteria)
      {
        params.AlgorithmDescription = "IMLP-MD";
        //params.AlgorithmDescription = "IMLP-MD_Verbose";
        params.algType = TestParameters::IMLP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        vctDynamicVector<vct3x3> dummySampleCov;  //  ''
        cisstAlgorithmICP_IMLP_MahalDist_PointCloud *pAlg =
          new cisstAlgorithmICP_IMLP_MahalDist_PointCloud(
          pTree, dummySamples, dummySampleCov, dummySampleCov, customParams.outlier_ChiSquareThreshold);
        params.pAlg = pAlg;
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

      // Run IMLP_CP (Closest Point Match Criteria)
      {
        params.AlgorithmDescription = "IMLP-CP";
        //params.AlgorithmDescription = "IMLP-CP_Verbose";
        params.algType = TestParameters::IMLP;
        SetOutputDir(params, outputCommonDir, outputSubFolder);

        vctDynamicVector<vct3> dummySamples;      // these will be set later by the sample generator routine
        vctDynamicVector<vct3x3> dummySampleCov;  //  ''
        cisstAlgorithmICP_IMLP_ClosestPoint_PointCloud *pAlg =
          new cisstAlgorithmICP_IMLP_ClosestPoint_PointCloud(
          pTree, dummySamples, dummySampleCov, dummySampleCov, customParams.outlier_ChiSquareThreshold);
        params.pAlg = pAlg;
        Run_ParameterizedTest(mesh_source, pTree, params);
        delete params.pAlg; params.pAlg = NULL;
      }

    }
  }
}
예제 #6
0
/* ********************************************************************* */
int Setup (Input *input, Cmd_Line *cmd_line, char *ini_file)
/*!
 * Open and parse the initialization file. 
 * Assign values to the input structure.
 *
 * \param [out]  input     pointer to an Input structure
 * \param [in]   cmd_line  pointer to a Cmd_Line structure (useful, e.g.,
 *                         to resize the domain using the \c -xres option)
 * \param [in]   ini_file  the name of the initialization file (default
 *                         is "pluto.ini") specified with the \c -i option.
 *
 *********************************************************************** */
{
  int    idim, ip, ipos, itype, nlines;
  char   *bound_opt[NOPT], str_var[512], *str;
  char  *glabel[]     = {"X1-grid", "X2-grid","X3-grid"};
  char  *bbeg_label[] = {"X1-beg", "X2-beg","X3-beg"};
  char  *bend_label[] = {"X1-end", "X2-end","X3-end"};
  double dbl_var, rx;
  Output *output;
  FILE *fp;

  for (itype = 0; itype < NOPT; itype++) {
    bound_opt[itype] = "0000";
  }

/*  ---------------------------------------------------
      available options are given as two set of names;
      This facilitates when updating the code and
      people are too lazy to read the manual !
    --------------------------------------------------- */

  bound_opt[OUTFLOW]      = "outflow";
  bound_opt[REFLECTIVE]   = "reflective";
  bound_opt[AXISYMMETRIC] = "axisymmetric";
  bound_opt[EQTSYMMETRIC] = "eqtsymmetric";
  bound_opt[PERIODIC]     = "periodic";
  bound_opt[SHEARING]     = "shearingbox";
  bound_opt[USERDEF]      = "userdef";

  input->log_freq = 1; /* -- default -- */
 
  nlines = ParamFileRead(ini_file);

/* ------------------------------------------------------------
                        [Grid] Section 
   ------------------------------------------------------------ */

  for (idim = 0; idim < 3; idim++){
    input->npatch[idim] = atoi(ParamFileGet(glabel[idim], 1));
    input->npoint[idim] = 0;

    ipos = 1;
    for (ip = 1; ip <= input->npatch[idim]; ip++) {

      input->patch_left_node[idim][ip] = atof(ParamFileGet(glabel[idim], ++ipos));
      input->patch_npoint[idim][ip]    = atoi(ParamFileGet(glabel[idim], ++ipos));
      input->npoint[idim]             += input->patch_npoint[idim][ip];
      input->grid_is_uniform[idim]     = 0;

      strcpy (str_var, ParamFileGet(glabel[idim], ++ipos)); 
/*
printf ("%f  %d %s\n",input->patch_left_node[idim][ip],input->patch_npoint[idim][ip],str_var);
*/
      if (strcmp(str_var,"u") == 0 || strcmp(str_var,"uniform") == 0) {
        input->patch_type[idim][ip] = UNIFORM_GRID;
        if (input->npatch[idim] == 1) input->grid_is_uniform[idim] = 1;        
      }else if (strcmp(str_var,"s") == 0 || strcmp(str_var,"strecthed") == 0) { 
        input->patch_type[idim][ip] = STRETCHED_GRID;
      }else if (strcmp(str_var,"l+") == 0){
        input->patch_type[idim][ip] = LOGARITHMIC_INC_GRID;
      }else if (strcmp(str_var,"l-") == 0){
        input->patch_type[idim][ip] = LOGARITHMIC_DEC_GRID;
      }else{ 
        printf ("\nSetup: You must specify either 'u', 's', 'l+' or 'l-' as grid-type in %s\n",
                ini_file);
        QUIT_PLUTO(1);
      }
    }
    
    input->patch_left_node[idim][ip] = atof(ParamFileGet(glabel[idim], ++ipos));

    if ( (ipos+1) != (input->npatch[idim]*3 + 3)) {
      printf ("! Setup: domain #%d setup is not properly defined \n", idim);
      QUIT_PLUTO(1);
    }
    if (idim >= DIMENSIONS && input->npoint[idim] != 1) {
      printf ("! Setup: %d point(s) on dim. %d is NOT valid, resetting to 1\n",
              input->npoint[idim],idim+1);
      input->npoint[idim]          = 1;
      input->npatch[idim]          = 1;
      input->patch_npoint[idim][1] = 1;
    }
  }

/* ------------------------------------------------------------
      Change the resolution if cmd_line->xres has been given
   ------------------------------------------------------------ */

  if (cmd_line->xres > 1) {
    rx =  (double)cmd_line->xres/(double)input->patch_npoint[IDIR][1];
    for (idim = 0; idim < DIMENSIONS; idim++){
      if (input->npatch[idim] > 1){  
        printf ("! Setup: -xres option works on uniform, single patch grid\n");
        QUIT_PLUTO(1);
      }
      
      dbl_var = (double)input->patch_npoint[idim][1];
      input->patch_npoint[idim][1] = MAX( (int)(dbl_var*rx), 1);
      dbl_var = (double)input->npoint[idim];
      input->npoint[idim] = MAX( (int)(dbl_var*rx), 1); 
    }  
  }

/* ------------------------------------------------------------
                     [Time] Section 
   ------------------------------------------------------------ */

  input->cfl         = atof(ParamFileGet("CFL", 1));

  if (ParamExist ("CFL_par")) input->cfl_par = atof(ParamFileGet("CFL_par", 1));
  else                            input->cfl_par = 0.8/(double)DIMENSIONS;

  if (ParamExist ("rmax_par")) input->rmax_par = atof(ParamFileGet("rmax_par", 1));
  else                             input->rmax_par = 100.0;

  input->cfl_max_var = atof(ParamFileGet("CFL_max_var", 1));
  input->tstop       = atof(ParamFileGet("tstop", 1));
  input->first_dt    = atof(ParamFileGet("first_dt", 1));

/* ------------------------------------------------------------
                     [Solver] Section 
   ------------------------------------------------------------ */

  sprintf (input->solv_type,"%s",ParamFileGet("Solver",1));

/* ------------------------------------------------------------
                     [Boundary] Section 
   ------------------------------------------------------------ */

  for (idim = 0; idim < 3; idim++){

    str = ParamFileGet(bbeg_label[idim], 1);
    COMPARE (str, bound_opt[itype], itype);
    if (itype == NOPT) {
      printf ("! Setup: don't know how to put left boundary '%s'  \n", str);
      QUIT_PLUTO(1);
    }
    input->lft_bound_side[idim] = itype;
  }

  for (idim = 0; idim < 3; idim++){

    str = ParamFileGet(bend_label[idim], 1);
    COMPARE (str, bound_opt[itype], itype);
    if (itype == NOPT) {
      printf ("! Setup: don't know how to put left boundary '%s'  \n", str);
      QUIT_PLUTO(1);
    }
    input->rgt_bound_side[idim] = itype;
  }

/* ------------------------------------------------------------
                     [Output] Section 
   ------------------------------------------------------------ */

  input->user_var = atoi(ParamFileGet("uservar", 1));
  for (ip = 0; ip < input->user_var; ip++){

    if ( (str = ParamFileGet("uservar", 2 + ip)) != NULL){
      sprintf (input->user_var_name[ip], "%s", str);
    }else{
      printf ("! Setup: missing name after user var name '%s'\n", 
              input->user_var_name[ip-1]);
      QUIT_PLUTO(1);
    } 
  }

/* ---- set output directory ---- */

  sprintf (input->output_dir, "%s","./");  /* default value is current directory */
  if (ParamExist("output_dir")){
    str = ParamFileGet("output_dir",1);
    sprintf (input->output_dir, "%s",str);
  }
  SetOutputDir(input->output_dir);

/* -- check if we have write access and if the directory exists -- */

  sprintf (str_var,"%s/tmp09123.txt",input->output_dir); /* -- test file -- */
  fp = fopen(str_var,"w");  /* -- open test file for writing -- */
  if (fp == NULL){
    printf ("! Setup: cannot access directory '%s'.\n", input->output_dir);
    printf ("!        Please check that the directory exists\n");
    printf ("!        and you have write permission.\n");
    QUIT_PLUTO(1);
  }else{
    fclose(fp);
    remove(str_var);  /* -- remove file -- */
  }

/* ---- dbl output ---- */

  ipos = 0;
  output = input->output + (ipos++);
  output->type  = DBL_OUTPUT;
  output->cgs   = 0;  /* cannot write .dbl using cgs units */
  GetOutputFrequency(output, "dbl");

  sprintf (output->mode,"%s",ParamFileGet("dbl",3));
  #ifdef USE_ASYNC_IO
   if (    strcmp(output->mode,"single_file") 
        && strcmp(output->mode,"single_file_async")
        && strcmp(output->mode,"multiple_files")){
      printf ("! Setup: expecting 'single_file', 'single_file_async' ");
      printf ("or 'multiple_files' in dbl output\n");
      QUIT_PLUTO(1);
   }
  #else
   if (   strcmp(output->mode,"single_file")
       && strcmp(output->mode,"multiple_files")){
      printf (
      "! Setup: expecting 'single_file' or 'multiple_files' in dbl output\n");
      QUIT_PLUTO(1);
   }     
  #endif

 /* ---- flt output ---- */

  if (ParamExist("flt")){
    output = input->output + (ipos++);
    output->type  = FLT_OUTPUT;
    GetOutputFrequency(output, "flt");

    sprintf (output->mode,"%s",ParamFileGet("flt",3));  
    #ifdef USE_ASYNC_IO
     if (    strcmp(output->mode,"single_file") 
          && strcmp(output->mode,"single_file_async")
          && strcmp(output->mode,"multiple_files")){
        printf ("! Setup: expecting 'single_file', 'single_file_async' ");
        printf ("or 'multiple_files' in flt output\n");
        QUIT_PLUTO(1);
     }
    #else
     if (    strcmp(output->mode,"single_file") 
          && strcmp(output->mode,"multiple_files")){
        printf (
        "! Setup: expecting 'single_file' or 'multiple_files' in flt output\n");
        QUIT_PLUTO(1);
     }  
    #endif
    if (ParamFileHasBoth ("flt","cgs")) output->cgs = 1;
    else                                output->cgs = 0;
  }

 /* -- hdf5 output -- */

  if (ParamExist("dbl.h5")){
    output = input->output + (ipos++);
    output->type  = DBL_H5_OUTPUT;
    output->cgs   = 0;  /* cannot write .h5 using cgs units */
    GetOutputFrequency(output, "dbl.h5");
  }
  if (ParamExist("flt.h5")){
    output = input->output + (ipos++);
    output->type  = FLT_H5_OUTPUT;
    output->cgs   = 0;  /* cannot write .h5 using cgs units */
    GetOutputFrequency(output, "flt.h5");
  }

 /* -- vtk output -- */

  if (ParamExist ("vtk")){
    output = input->output + (ipos++);
    output->type  = VTK_OUTPUT;
    GetOutputFrequency(output, "vtk");

    if (ParamFileGet("vtk",3) == NULL){
      printf ("! Setup: extra field missing in vtk output\n");
      QUIT_PLUTO(1);
    }
    sprintf (output->mode,"%s",ParamFileGet("vtk",3));
    if (   strcmp(output->mode,"single_file")
        && strcmp(output->mode,"multiple_files")){
       printf ("! Setup: expecting 'single_file' or 'multiple_files' in\n");
       printf ("         vtk output\n");
       QUIT_PLUTO(1);
    }
    if (ParamFileHasBoth ("vtk","cgs")) output->cgs = 1;
    else                                output->cgs = 0;
  }

 /* -- tab output -- */

  if (ParamExist ("tab")){
    output = input->output + (ipos++);
    output->type  = TAB_OUTPUT;
    GetOutputFrequency(output, "tab");
    if (ParamFileHasBoth ("tab","cgs")) output->cgs = 1;
    else                                output->cgs = 0;
  }

 /* -- ppm output -- */

  if (ParamExist ("ppm")){
    output = input->output + (ipos++);
    output->type  = PPM_OUTPUT;
    output->cgs   = 0;   /* Cannot write ppm in cgs units */
    GetOutputFrequency(output, "ppm");
  }

 /* -- png output -- */

  if (ParamExist ("png")){
    output = input->output + (ipos++);
    output->type  = PNG_OUTPUT;
    output->cgs   = 0;   /* Cannot write png in cgs units */
    GetOutputFrequency(output, "png");
  }


 /* -- log frequency -- */

  input->log_freq = atoi(ParamFileGet("log", 1));
  input->log_freq = MAX(input->log_freq, 1);
  
 /* -- set default for remaining output type -- */

  while (ipos < MAX_OUTPUT_TYPES){
    output = input->output + ipos;
    output->type   = -1;
    output->cgs    =  0;
    output->dt     = -1.0;
    output->dn     = -1;
    output->dclock = -1.0;
    ipos++;
  }

 /* -- analysis -- */

  if (ParamExist ("analysis")){
    input->anl_dt = atof(ParamFileGet("analysis", 1));
    input->anl_dn = atoi(ParamFileGet("analysis", 2));
  }else{
    input->anl_dt = -1.0;   /* -- defaults -- */
    input->anl_dn = -1;
  }

/* ------------------------------------------------------------
                   [Parameters] Section 
   ------------------------------------------------------------ */

  fp = fopen(ini_file,"r");
  
/* -- find position at "[Parameters" -- */

  for (ipos = 0; ipos <= nlines; ipos++){ 
    fgets(str_var, 512, fp);
    
    if (strlen(str_var) > 0) {
      str = strtok (str_var,"]");
      if (strcmp(str,"[Parameters") == 0) break;
    }
  }

  fgets(str_var, 512, fp); 
  
  for (ip = 0; ip < USER_DEF_PARAMETERS; ip++){
    fscanf (fp,"%s \n", str_var);
    dbl_var = atof(ParamFileGet(str_var,1));
    input->aux[ip] = dbl_var;
    fgets(str_var, sizeof(str_var), fp); /* use fgets to advance to next line */
  }
  fclose(fp);

  return(0);
}