Example #1
0
string CViewRenderer::renderFile(const IRenderingContext * context, const string & sourceFile, CDT & data, bool ret) throw (CException)
{
    boost::filesystem::path sourcePath(sourceFile);
    if (!boost::filesystem::exists(sourcePath)) {
        throw CException("View file \"" + sourceFile + "\" does not exist.");
    }
    string viewFile = getViewFile(sourceFile);
    boost::filesystem::path viewPath(viewFile);
    if (!boost::filesystem::exists(viewPath) || boost::filesystem::last_write_time(sourcePath) > boost::filesystem::last_write_time(viewPath)) {
        if (generateViewFile(sourceFile, viewFile)) {
            chmod(viewFile.c_str(), filePermission);
        } else {
            throw CException("Can't generate view file \"" + viewFile + "\" from source file \"" + sourceFile + "\".");
        }
    }

    if (context != 0) {
    	return context->renderInternal(viewFile, data, ret);
    }

	stringstream os;
	StreamOutputCollector outputCollector(os);
    TDynamicTemplateCacheMap::const_iterator found = _templateCache.find(viewFile);

	VMLoader * oLoader = 0;
	if (found == _templateCache.end()) {
		oLoader = new VMFileLoader(viewFile.c_str());
		_templateCache[viewFile.c_str()] = boost::shared_ptr<VMLoader>(oLoader);
	} else {
		oLoader = found->second.get();
	}

	PROFILE_BEGIN("CViewRenderer::rendering template bytecode of \"" + viewFile + "\"")
	UINT_32 iIP = 0;
	VM * vm = Cws::app()->getTemplateEngine()->getVM();
	const VMMemoryCore * pVMMemoryCore = oLoader->GetCore();
	vm->Init(pVMMemoryCore, &outputCollector, 0);
	vm->Run(pVMMemoryCore, &outputCollector, iIP, data, 0);
	PROFILE_END()

	if (ret) {
		return os.str();
	} else {
		Cws::app()->getOutputStack().top()->echo(os.str());
		return "";
	}
}
Example #2
0
/**
 * @function main
 */
int main( int argc, char* argv[] ) {
  
  double sx; double sy; double sz;
  double ox; double oy; double oz;
  double resolution;

  sx = 1.0; sy = 1.0; sz = 1.0;
  ox = 0.0; oy = 0.0; oz = 0.0;
  resolution = 0.0125;
  
  // Distance Field
  printf("Create PF Distance Field \n");
  PFDistanceField pf( sx, sy, sz, resolution, ox, oy, oz );
  pf.reset();

  // Geometry
  double bx; double by; double bz;
  bx = 0.2; by = 0.25; bz = 0.2;

  pf.addBox( 0.6, 0.5, 0.1, bx, by, bz );
  pf.addBox( 0.6, 0.5, 0.1, bx + 0.0, by + 0.0, bz + 0.5 );

  // Settings parameters
  int cost = 10; int radius = 3; int numPaths = 6;

  DiversePaths dp( &pf, radius, cost );

  // Set goal and start
  std::vector<double> goal(3);
  goal[0] = 0.5; goal[1] = 0.9; goal[2] = 0.7;
  std::vector<double> start(3);
  start[0] = 0.3; start[1] = 0.1; start[2] = 0.5;

  // Paths
  std::vector<std::vector<double> > midPoints;
  std::vector<std::vector<std::vector<double> > > paths;

  // Get paths
  float boundFactor = 2.0;
  int numCheckPoints = 10;
  time_t ts = clock();
  paths = dp.getDiversePaths2( start, goal, numPaths, midPoints, boundFactor, numCheckPoints );
  time_t tf = clock();
  double dt = (double) ( tf - ts ) / CLOCKS_PER_SEC;
  printf( "** getDiversePaths2 time: %f \n", dt );

  printf( "Num points: %d \n", midPoints.size() );

  // Create viewer
  boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = createViewer();

  // View the path
  reset_PCL_Tools_counters();

  // MidPoints: View pointcloud (NOT BOTH Balls and pointcloud)
   viewPoints( midPoints, viewer, 255,0,255 );

   // Get checkPoint Lines
   std::vector<std::vector<std::vector<double> > > checkLines;
   if( paths.size() >= 2 ) {
     checkLines = dp.getCheckPointLines( paths[0], paths[2], numCheckPoints );
   } else {
     printf( " !! Only one path, no drawing checkPoint lines! \n" );
   }

   for( int i = 0; i < checkLines.size(); ++i ) {
     viewPath( checkLines[i], viewer, 0, 0, 255 );
   }

  dp.visualizePaths( viewer, paths, true );

  // Loop
  while( !viewer->wasStopped() ) {
    viewer->spinOnce(100);
    boost::this_thread::sleep( boost::posix_time::microseconds(100000));
    } 

  printf("End of program \n");
  return(0);
}