コード例 #1
0
ファイル: late_parser.cpp プロジェクト: robojeb/Late
_sub_production_ast handle_sub_production(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _sub_production_ast out;
  _symbol_ast symbol;
  switch(p.number()){
    case 0: //symbol ws sub_production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      symbol = handle_symbol(input, production, chart);

      //Skip ws
      tie(setIndex, stateIndex) = p.symbolInfo(2);
      production = chart.getState(setIndex, stateIndex).first;
      out = handle_sub_production(input, production, chart);

      out.insert(out.begin(), symbol);
      return out;
    case 1: //symbol
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      symbol = handle_symbol(input, production, chart);

      out.push_back(symbol);

      return out;
    default:;
  }
  return out;
}
コード例 #2
0
ファイル: charteditorwindow.cpp プロジェクト: emoratac/devel
void ChartEditorWindow::onActionFetchLayersFromDBTriggered(){
    Chart chart;
    QString qSqlDriverStr;
    LayerSelectionItem* selItem;
    QString layerId;
    QStringList layerIdList;

    layerSelectionVector.clear();

    if(settingsManager->getDBDriver() == "MySQL")
        qSqlDriverStr = "QMYSQL";
    else if (settingsManager->getDBDriver() == "PostgreSQL")
        qSqlDriverStr = "QPSQL";

    chart.setOGRDriverQt(qSqlDriverStr);
    layerIdList << chart.getSimplifiedLayers();

    QStringListIterator layerIdListIt(layerIdList);
    while(layerIdListIt.hasNext()){
        layerId = layerIdListIt.next();
        selItem = new LayerSelectionItem(layerId, true);
        layerSelectionVector << selItem;
    }

    showLayers();
}
コード例 #3
0
ファイル: late_parser.cpp プロジェクト: robojeb/Late
_file_ast handle_file(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _production_ast p_ast;
  _file_ast out;
  switch (p.number()){
    case 0: //production ws ";" ws file
      //production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      p_ast = handle_production(input, production, chart);
      //We don't care about whitespace or the symbol in this case
      tie(setIndex, stateIndex) = p.symbolInfo(4);
      production = chart.getState(setIndex, stateIndex).first;
      out = handle_file(input, production, chart);
      out.push_back(p_ast);
      return out;
    case 1: // production ws ";" ws
      //This is the terminal file make a new
      //production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      p_ast = handle_production(input, production, chart);
      out = _file_ast({p_ast});
      return out;
    default:
      break;
  }
  return _file_ast{};
}
コード例 #4
0
void ParserCKYBest::process_internal_rules(Chart& chart) const
{
  unsigned sent_size=chart.get_size();
  for (unsigned span = 2; span <= sent_size; ++span) {
    unsigned end_of_begin=sent_size-span;
    for (unsigned begin=0; begin <= end_of_begin; ++begin) {
    	unsigned end = begin + span -1;

      //      std::cout << "begin: " << begin << ", end: " << end << std::endl;

    	Cell& result_cell = chart.access(begin,end);

    	if(!result_cell.is_closed()) {
    		// look for all possible new edges
    		for (unsigned m = begin; m < end; ++m) {
    			const Cell& left_cell = chart.access(begin,m);
    			if(!left_cell.is_closed()) {
    				const Cell& right_cell = chart.access(m+1,end);
    				if( !right_cell.is_closed())
    					get_candidates(left_cell,right_cell,result_cell);
    			}
    		}
    		// std::cout << result_cell << std::endl;

    		add_unary(result_cell, span == sent_size);

	//	result_cell.apply_beam();
      }
      // std::cout << result_cell << std::endl;
    }
  }
}
コード例 #5
0
ファイル: chart.cpp プロジェクト: fredy4eg/2
void Run()
{	
	int i;
	Chart a;	
	ifstream input("input.txt");
	input>>i;
	for(int j=0; j<i;j++)
	{
		string s;
		input>>s;
		if(s=="VOTE")
		{
			string s1;
			int q;
			input>>s1>>q;
			a.VoteRecord(s1,q);
		}
		if(s=="TOP")
		{
			string s1;
			int q;
			input>>s1>>q;
			vector<int> b;
			b=a.GetTop(s1,q);
			cout<<"Топ для "<<s1<<":\n";
			for(int i=0;i<b.size();i++)
				cout<<b[i]<<" ";
			cout<<"\n";
		}
コード例 #6
0
ファイル: late_parser.cpp プロジェクト: robojeb/Late
_rhs_ast handle_rhs(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _rhs_ast out;
  _sub_production_ast subProd;
  switch(p.number()){
    case 0: //sub_production ws "|" ws rhs | sub_production
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      subProd = handle_sub_production(input, production, chart);

      tie(setIndex, stateIndex) = p.symbolInfo(4);
      production = chart.getState(setIndex, stateIndex).first;
      out = handle_rhs(input, production, chart);

      out.push_back(subProd);
      return out;
    case 1:
      tie(setIndex, stateIndex) = p.symbolInfo(0);
      production = chart.getState(setIndex, stateIndex).first;
      subProd = handle_sub_production(input, production, chart);

      out.push_back(subProd);
      return out;
    default:;
  }
  return out;
}
コード例 #7
0
ファイル: late_parser.cpp プロジェクト: robojeb/Late
_production_ast handle_production(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _production_ast out = _production_ast();
  //No cases so no switch
  //non_terminal option ws ":=" ws rhs

  tie(setIndex, stateIndex) = p.symbolInfo(0);
  production = chart.getState(setIndex, stateIndex).first;
  _non_terminal_ast name = handle_non_terminal(input, production, chart);

  out.name_ = name;

  tie(setIndex, stateIndex) = p.symbolInfo(1);
  if(setIndex > 0) { //If it has a negative setIndex it was skipped
    production = chart.getState(setIndex, stateIndex).first;
    _option_ast option = handle_option(input, production, chart);

    if (option == "nullable") {
      out.nullable_ = true;
    } else {
      out.nullable_ = false;
    }
  }

  tie(setIndex, stateIndex) = p.symbolInfo(5);
  production = chart.getState(setIndex, stateIndex).first;
  _rhs_ast rhs = handle_rhs(input, production, chart);

  out.sub_productions_ = rhs;

  return out;
}
コード例 #8
0
ファイル: Atlas.cpp プロジェクト: maleiwhat/thekla_atlas
void Atlas::extractCharts()
{
    const uint faceCount = m_mesh->faceCount();

    int first = 0;
    Array<uint> queue(faceCount);

    BitArray bitFlags(faceCount);
    bitFlags.clearAll();

    for (uint f = 0; f < faceCount; f++)
    {
        if (bitFlags.bitAt(f) == false)
        {
            // Start new patch. Reset queue.
            first = 0;
            queue.clear();
            queue.append(f);
            bitFlags.setBitAt(f);

            while (first != queue.count())
            {
                const HalfEdge::Face * face = m_mesh->faceAt(queue[first]);

                // Visit face neighbors of queue[first]
                for (HalfEdge::Face::ConstEdgeIterator it(face->edges()); !it.isDone(); it.advance())
                {
                    const HalfEdge::Edge * edge = it.current();
                    nvDebugCheck(edge->pair != NULL);

                    if (!edge->isBoundary() && /*!edge->isSeam()*/ 
                        //!(edge->from()->tex() != edge->pair()->to()->tex() || edge->to()->tex() != edge->pair()->from()->tex()))
                        !(edge->from() != edge->pair->to() || edge->to() != edge->pair->from())) // Preserve existing seams (not just texture seams).
                    {
                        const HalfEdge::Face * neighborFace = edge->pair->face;
                        nvDebugCheck(neighborFace != NULL);

                        if (bitFlags.bitAt(neighborFace->id) == false)
                        {
                            queue.append(neighborFace->id);
                            bitFlags.setBitAt(neighborFace->id);
                        }
                    }
                }

                first++;
            }

            Chart * chart = new Chart();
            chart->build(m_mesh, queue);

            m_chartArray.append(chart);
        }
    }
}
コード例 #9
0
void ParserCKYBest::parse(Chart& chart) const
{
  bool isroot = chart.get_size() == 1;
  for(unsigned i = 0; i < chart.get_size(); ++i) {
    //    std::cout << "initialising position: " << i << std::endl;
    add_unary_init(chart.access(i,i),isroot);
    //    std::cout << chart.access(i,i) << std::endl;
  }

  process_internal_rules(chart);
}
コード例 #10
0
void
CrossSectionWindow::PaintGrid(Canvas &canvas, Chart &chart)
{
  canvas.SetTextColor(look.text_color);

  chart.DrawXGrid(Units::ToSysDistance(fixed(5)), fixed_zero,
                  look.grid_pen, fixed(5), true);
  chart.DrawYGrid(Units::ToSysAltitude(fixed(1000)), fixed_zero,
                  look.grid_pen, fixed(1000), true);

  chart.DrawXLabel(_T("D"));
  chart.DrawYLabel(_T("h"));
}
コード例 #11
0
    /**
     * \brief create a branch marker between two nodes and store it into marker array
     */
    virtual void createBranchMarker(const Chart &child, const Chart &parent)
    {
        if (!markers){
            ROS_WARN_THROTTLE(30,"[ExplorerBase::%s]\tNo marker array to update is provided, visualization is disabled.",__func__);
            return;
        }
        geometry_msgs::Point e;
        geometry_msgs::Point s;

        visualization_msgs::Marker branch;
        branch.header.frame_id = mark_frame;
        branch.header.stamp = ros::Time();
        branch.lifetime = ros::Duration(0.5);
        branch.ns = "Atlas Branches";
        //need to know the branch id, too bad branches don't have it.
        //Lets use Cantor pairing function: 0.5(a+b)(a+b+1)+b
        branch.id = 0.5*(child.getId() + parent.getId())*(child.getId()+parent.getId()+1) + parent.getId();
        branch.type = visualization_msgs::Marker::LINE_STRIP;
        branch.action = visualization_msgs::Marker::ADD;
        s.x = child.getCenter()[0];
        s.y = child.getCenter()[1];
        s.z = child.getCenter()[2];
        branch.points.push_back(s);
        e.x = parent.getCenter()[0];
        e.y = parent.getCenter()[1];
        e.z = parent.getCenter()[2];
        branch.points.push_back(e);
        branch.scale.x = 0.005;
        branch.color.a = 1.0;
        branch.color.r = 0.0;
        branch.color.g = 0.0;
        branch.color.b = 0.9;
        std::lock_guard<std::mutex> guard(*mtx_ptr);
        markers->markers.push_back(branch);
    }
コード例 #12
0
ファイル: CmdBurndown.cpp プロジェクト: georgebrock/task
int CmdBurndownMonthly::execute (std::string& output)
{
  int rc = 0;

  // Scan the pending tasks, applying any filter.
  handleRecurrence ();
  std::vector <Task> filtered;
  filter (filtered);
  context.tdb2.commit ();

  // Create a chart, scan the tasks, then render.
  Chart chart ('M');
  chart.scan (filtered);
  output = chart.render ();
  return rc;
}
コード例 #13
0
ファイル: pmchart.cpp プロジェクト: felipebetancur/pcp
//
// Note: Called from both Apply and OK on New Chart dialog
// Must only called when the changes are definately going to
// be applied, so all input validation must be done by now.
//
Chart *PmChart::acceptNewChart()
{
    bool yAutoScale;
    double yMin, yMax;
    QString scheme;
    int sequence;

    Chart *cp = new Chart(activeTab(), activeTab()->splitter());
    activeGroup->addGadget(cp);
    activeTab()->addGadget(cp);

    QString newTitle = my.newchart->title().trimmed();
    if (newTitle.isEmpty() == false)
	cp->changeTitle(newTitle, true);
    cp->setLegendVisible(my.newchart->legend());
    cp->setAntiAliasing(my.newchart->antiAliasing());
    cp->setRateConvert(my.newchart->rateConvert());
    my.newchart->updateChartPlots(cp);
    my.newchart->scale(&yAutoScale, &yMin, &yMax);
    cp->setScale(yAutoScale, yMin, yMax);
    my.newchart->scheme(&scheme, &sequence);
    cp->setScheme(scheme, sequence);

    activeGroup->setupWorldView();
    activeTab()->showGadgets();

    enableUi();
    return cp;
}
コード例 #14
0
void
CrossSectionWindow::PaintAircraft(Canvas &canvas, const Chart &chart,
                                  const PixelRect rc)
{
  canvas.Select(look.aircraft_brush);
  canvas.SelectNullPen();

  RasterPoint line[4];
  line[0].x = chart.screenX(fixed_zero);
  line[0].y = chart.screenY(gps_info.nav_altitude);
  line[1].x = rc.left;
  line[1].y = line[0].y;
  line[2].x = line[1].x;
  line[2].y = line[0].y - (line[0].x - line[1].x) / 2;
  line[3].x = (line[1].x + line[0].x) / 2;
  line[3].y = line[0].y;
  canvas.DrawTriangleFan(line, 4);
}
コード例 #15
0
ファイル: CrossSectionWindow.cpp プロジェクト: Mrdini/XCSoar
void
CrossSectionWindow::PaintGlide(Chart &chart)
{
  if (gps_info.GroundSpeed > fixed(10)) {
    fixed t = vec.Distance / gps_info.GroundSpeed;
    chart.DrawLine(fixed_zero, gps_info.NavAltitude, vec.Distance,
                   gps_info.NavAltitude + calculated_info.Average30s * t,
                   Chart::STYLE_BLUETHIN);
  }
}
コード例 #16
0
void
CrossSectionWindow::PaintGlide(Chart &chart)
{
  if (gps_info.ground_speed > fixed(10)) {
    fixed t = vec.distance / gps_info.ground_speed;
    chart.DrawLine(fixed_zero, gps_info.nav_altitude, vec.distance,
                   gps_info.nav_altitude + calculated_info.average * t,
                   ChartLook::STYLE_BLUETHIN);
  }
}
コード例 #17
0
ファイル: CrossSectionWindow.cpp プロジェクト: Mrdini/XCSoar
void
CrossSectionWindow::PaintAircraft(Canvas &canvas, const Chart &chart,
                                  const PixelRect rc)
{
  Brush brush(text_color);
  canvas.select(brush);

  Pen pen(1, text_color);
  canvas.select(pen);

  RasterPoint line[4];
  line[0].x = chart.screenX(fixed_zero);
  line[0].y = chart.screenY(gps_info.NavAltitude);
  line[1].x = rc.left;
  line[1].y = line[0].y;
  line[2].x = line[1].x;
  line[2].y = line[0].y - (line[0].x - line[1].x) / 2;
  line[3].x = (line[1].x + line[0].x) / 2;
  line[3].y = line[0].y;
  canvas.polygon(line, 4);
}
コード例 #18
0
ファイル: pmchart.cpp プロジェクト: felipebetancur/pcp
void PmChart::acceptEditChart()
{
    bool yAutoScale;
    double yMin, yMax;
    QString scheme;
    int sequence;

    Chart *cp = my.newchart->chart();
    QString editTitle = my.newchart->title().trimmed();
    if (editTitle.isEmpty() == false && editTitle != cp->title())
	cp->changeTitle(editTitle, true);
    cp->setLegendVisible(my.newchart->legend());
    cp->setAntiAliasing(my.newchart->antiAliasing());
    cp->setRateConvert(my.newchart->rateConvert());
    my.newchart->scale(&yAutoScale, &yMin, &yMax);
    cp->setScale(yAutoScale, yMin, yMax);
    my.newchart->updateChartPlots(cp);
    my.newchart->scheme(&scheme, &sequence);
    cp->setScheme(scheme, sequence);
    cp->replot();
    cp->show();

    enableUi();
}
コード例 #19
0
ファイル: late_parser.cpp プロジェクト: robojeb/Late
//Handle symbols
_symbol_ast handle_symbol(string& input, Production& p, Chart& chart)
{
  int64_t setIndex;
  size_t stateIndex;
  Production production;
  _symbol_ast out;
  tie(setIndex, stateIndex) = p.symbolInfo(0);
  production = chart.getState(setIndex, stateIndex).first;
  out.value_ = handle_non_terminal(input, production, chart);
  switch(p.number()){
    case 0:
      out.type_ = _symbol_ast::type::NON_TERMINAL;
      break;
    case 1:
      out.type_ = _symbol_ast::type::TERMINAL;
      break;
    case 2:
      out.type_ = _symbol_ast::type::REGEX;
      break;
    default:;
  }
  return out;
}
コード例 #20
0
void
CrossSectionWindow::PaintTerrain(Canvas &canvas, Chart &chart)
{
  if (terrain == NULL)
    return;

  const GeoPoint p_diff = vec.EndPoint(start) - start;

  RasterTerrain::Lease map(*terrain);

  RasterPoint points[2 + AIRSPACE_SCANSIZE_X];

  points[0].x = chart.screenX(vec.distance);
  points[0].y = chart.screenY(fixed_zero);
  points[1].x = chart.screenX(fixed_zero);
  points[1].y = chart.screenY(fixed_zero);

  unsigned i = 2;
  for (unsigned j = 0; j < AIRSPACE_SCANSIZE_X; ++j) {
    const fixed t_this = fixed(j) / (AIRSPACE_SCANSIZE_X - 1);
    const GeoPoint p_this = start + p_diff * t_this;

    short h = map->GetHeight(p_this);
    if (RasterBuffer::is_special(h)) {
      if (RasterBuffer::is_water(h))
        /* water is at 0m MSL */
        /* XXX paint in blue? */
        h = 0;
      else
        /* skip "unknown" values */
        continue;
    }

    points[i].x = chart.screenX(t_this * vec.distance);
    points[i].y = chart.screenY(fixed(h));
    i++;
  }

  if (i >= 4) {
    canvas.SelectNullPen();
    canvas.Select(look.terrain_brush);
    canvas.polygon(&points[0], i);
  }
}
コード例 #21
0
 /**
  * \brief create a marker from a chart and stores it into markers array
  */
 virtual void createNodeMarker(const Chart &c)
 {
     if (!markers){
         ROS_WARN_THROTTLE(30,"[ExplorerBase::%s]\tNo marker array to update is provided, visualization is disabled.",__func__);
         return;
     }
     visualization_msgs::Marker disc;
     disc.header.frame_id = mark_frame;
     disc.header.stamp = ros::Time();
     disc.lifetime = ros::Duration(0.5);
     disc.ns = "Atlas Nodes";
     disc.id = c.getId();
     disc.type = visualization_msgs::Marker::CYLINDER;
     disc.action = visualization_msgs::Marker::ADD;
     disc.scale.x = c.getRadius()*2;
     disc.scale.y = c.getRadius()*2;
     disc.scale.z = 0.001;
     disc.color.a = 0.75;
     disc.color.r = 0.3;
     disc.color.b = 0.35;
     disc.color.g = 0.5;
     Eigen::Matrix3d rot;
     rot.col(0) =  c.getTanBasisOne();
     rot.col(1) =  c.getTanBasisTwo();
     rot.col(2) =  c.getNormal();
     Eigen::Quaterniond q(rot);
     q.normalize();
     disc.pose.orientation.x = q.x();
     disc.pose.orientation.y = q.y();
     disc.pose.orientation.z = q.z();
     disc.pose.orientation.w = q.w();
     disc.pose.position.x = c.getCenter()[0];
     disc.pose.position.y = c.getCenter()[1];
     disc.pose.position.z = c.getCenter()[2];
     std::lock_guard<std::mutex> guard(*mtx_ptr);
     markers->markers.push_back(disc);
 }
コード例 #22
0
ファイル: Atlas.cpp プロジェクト: maleiwhat/thekla_atlas
void Atlas::parameterizeCharts()
{
    ParameterizationQuality globalParameterizationQuality;

    // Paramterize the charts.
    uint diskCount = 0;
    const uint chartCount = m_chartArray.count();
    for (uint i = 0; i < chartCount; i++)\
    {
        Chart * chart = m_chartArray[i];

        bool isValid = false;

        if (chart->isDisk())
        {
            diskCount++;

            ParameterizationQuality chartParameterizationQuality;

            if (chart->faceCount() == 1) {
                computeSingleFaceMap(chart->unifiedMesh());

                chartParameterizationQuality = ParameterizationQuality(chart->unifiedMesh());
            }
            else {
                computeOrthogonalProjectionMap(chart->unifiedMesh());
                ParameterizationQuality orthogonalQuality(chart->unifiedMesh());

                computeLeastSquaresConformalMap(chart->unifiedMesh());
                ParameterizationQuality lscmQuality(chart->unifiedMesh());
                
                // If the orthogonal projection produces better results, just use that. @@ Make sure the orthogonal map is valid has no overlaps.
                /*if (orthogonalQuality.rmsStretchMetric() < lscmQuality.rmsStretchMetric()) {
                    computeOrthogonalProjectionMap(chart->unifiedMesh());
                    chartParameterizationQuality = orthogonalQuality;
                }
                else*/ {
                    chartParameterizationQuality = lscmQuality;
                }

                // If conformal map failed, 

                // @@ Experiment with other parameterization methods.
                //computeCircularBoundaryMap(chart->unifiedMesh());
                //computeConformalMap(chart->unifiedMesh());
                //computeNaturalConformalMap(chart->unifiedMesh());
                //computeGuidanceGradientMap(chart->unifiedMesh());
            }

            //ParameterizationQuality chartParameterizationQuality(chart->unifiedMesh());

            isValid = chartParameterizationQuality.isValid();

            if (!isValid)
            {
                nvDebug("*** Invalid parameterization.\n");
#if 0
                // Dump mesh to inspect problem:
                static int pieceCount = 0;
            
                StringBuilder fileName;
                fileName.format("invalid_chart_%d.obj", pieceCount++);
                exportMesh(chart->unifiedMesh(), fileName.str()); 
#endif
            }

            // @@ Check that parameterization quality is above a certain threshold.

            // @@ Detect boundary self-intersections.

            globalParameterizationQuality += chartParameterizationQuality;
        }

        if (!isValid)
        {
            //nvDebugBreak();
            // @@ Run the builder again, but only on this chart.
            //AtlasBuilder builder(chart->chartMesh());
        }

        // Transfer parameterization from unified mesh to chart mesh.
        chart->transferParameterization();

    }

    nvDebug("  Parameterized %d/%d charts.\n", diskCount, chartCount);
    nvDebug("  RMS stretch metric: %f\n", globalParameterizationQuality.rmsStretchMetric());
    nvDebug("  MAX stretch metric: %f\n", globalParameterizationQuality.maxStretchMetric());
    nvDebug("  RMS conformal metric: %f\n", globalParameterizationQuality.rmsConformalMetric());
    nvDebug("  RMS authalic metric: %f\n", globalParameterizationQuality.maxAuthalicMetric());
}
コード例 #23
0
ファイル: Atlas.cpp プロジェクト: maleiwhat/thekla_atlas
void Atlas::computeCharts(const SegmentationSettings & settings)
{
    AtlasBuilder builder(m_mesh);

    // Tweak these values:
    const float maxThreshold = 2;
    const uint growFaceCount = 32;
    const uint maxIterations = 4;
    
    builder.settings = settings;

    //builder.settings.proxyFitMetricWeight *= 0.75; // relax proxy fit weight during initial seed placement.
    //builder.settings.roundnessMetricWeight = 0;
    //builder.settings.straightnessMetricWeight = 0;

    // This seems a reasonable estimate.
    uint maxSeedCount = max(6U, m_mesh->faceCount());

    // Create initial charts greedely.
    nvDebug("### Placing seeds\n");
    builder.placeSeeds(maxThreshold, maxSeedCount);
    nvDebug("###   Placed %d seeds (max = %d)\n", builder.chartCount(), maxSeedCount);

    builder.updateProxies();

    builder.mergeCharts();

#if 1
    nvDebug("### Relocating seeds\n");
    builder.relocateSeeds();

    nvDebug("### Reset charts\n");
    builder.resetCharts();

    builder.settings = settings;

    nvDebug("### Growing charts\n");

    // Restart process growing charts in parallel.
    uint iteration = 0;
    while (true)
    {
        if (!builder.growCharts(maxThreshold, growFaceCount))
        {
            nvDebug("### Can't grow anymore\n");

            // If charts cannot grow more: fill holes, merge charts, relocate seeds and start new iteration.

            nvDebug("### Filling holes\n");
            builder.fillHoles(maxThreshold);
            nvDebug("###   Using %d charts now\n", builder.chartCount());

            builder.updateProxies();

            nvDebug("### Merging charts\n");
            builder.mergeCharts();
            nvDebug("###   Using %d charts now\n", builder.chartCount());

            nvDebug("### Reseeding\n");
            if (!builder.relocateSeeds())
            {
                nvDebug("### Cannot relocate seeds anymore\n");

                // Done!
                break;
            }

            if (iteration == maxIterations)
            {
                nvDebug("### Reached iteration limit\n");
                break;
            }
            iteration++;

            nvDebug("### Reset charts\n");
            builder.resetCharts();

            nvDebug("### Growing charts\n");
        }
    };
#endif

    // Make sure no holes are left!
    nvDebugCheck(builder.facesLeft == 0);

    const uint chartCount = builder.chartArray.count();
    for (uint i = 0; i < chartCount; i++)
    {
        Chart * chart = new Chart();
        m_chartArray.append(chart);

        chart->build(m_mesh, builder.chartFaces(i));
    }

    // Build face indices.
    m_faceChart.resize(m_mesh->faceCount());
    m_faceIndex.resize(m_mesh->faceCount());

    for (uint i = 0; i < chartCount; i++)
    {
        const Chart * chart = m_chartArray[i];

        const uint faceCount = chart->faceCount();
        for (uint f = 0; f < faceCount; f++)
        {
            uint idx = chart->faceAt(f);
            m_faceChart[idx] = i;
            m_faceIndex[idx] = f;
        }
    }

    // Build an exclusive prefix sum of the chart vertex counts.
    m_chartVertexCountPrefixSum.resize(chartCount);
    
    if (chartCount > 0)
    {
        m_chartVertexCountPrefixSum[0] = 0;
        
        for (uint i = 1; i < chartCount; i++)
        {
            const Chart * chart = m_chartArray[i-1];
            m_chartVertexCountPrefixSum[i] = m_chartVertexCountPrefixSum[i-1] + chart->vertexCount();
        }

        m_totalVertexCount = m_chartVertexCountPrefixSum[chartCount - 1] + m_chartArray[chartCount-1]->vertexCount();
    }
    else
    {
        m_totalVertexCount = 0;
    }
   
}
コード例 #24
0
    virtual void createSamplesMarker(const Chart &c, const Eigen::Vector3d &projected)
    {
        if (c.samp_chosen < 0 || no_sample_markers)
            return;
        for (size_t i=0; i<c.samples.rows(); ++i)
        {
            visualization_msgs::Marker samp;
            samp.header.frame_id = mark_frame;
            samp.header.stamp = ros::Time();
            samp.lifetime = ros::Duration(0.5);
            samp.ns = "Atlas Node(" + std::to_string(c.getId()) + ") Samples";
            samp.id = i;
            samp.type = visualization_msgs::Marker::SPHERE;
            samp.action = visualization_msgs::Marker::ADD;
            samp.scale.x = 0.01;
            samp.scale.y = 0.01;
            samp.scale.z = 0.01;
            samp.color.a = 0.8;
            if (i==c.samp_chosen){
                //is winner
                samp.color.r = 0.6;
                samp.color.b = 0.0;
                samp.color.g = 0.0;
            }
            else{
                samp.color.r = 0.6;
                samp.color.b = 0.0;
                samp.color.g = 0.6;
            }
            samp.pose.position.x = c.samples(i,0);
            samp.pose.position.y = c.samples(i,1);
            samp.pose.position.z = c.samples(i,2);
            std::lock_guard<std::mutex> guard(*mtx_ptr);
            markers->markers.push_back(samp);
        }
        geometry_msgs::Point e;
        geometry_msgs::Point s;

        visualization_msgs::Marker proj;
        proj.header.frame_id = mark_frame;
        proj.header.stamp = ros::Time();
        proj.lifetime = ros::Duration(0.5);
        proj.ns = "Atlas Node(" + std::to_string(c.getId()) + ") Samples";
        proj.id = c.samples.rows();
        proj.type = visualization_msgs::Marker::ARROW;
        proj.action = visualization_msgs::Marker::ADD;
        s.x = c.samples(0,0);
        s.y = c.samples(0,1);
        s.z = c.samples(0,2);
        proj.points.push_back(s);
        e.x = projected[0];
        e.y = projected[1];
        e.z = projected[2];
        proj.points.push_back(e);
        proj.scale.x = 0.001;
        proj.scale.y = 0.01;
        proj.scale.z = 0.01;
        proj.color.a = 0.4;
        proj.color.r = 0.0;
        proj.color.g = 0.2;
        proj.color.b = 0.8;
        std::lock_guard<std::mutex> guard(*mtx_ptr);
        markers->markers.push_back(proj);
    }
コード例 #25
0
ファイル: client.cpp プロジェクト: reynev/Tic_tac_toe
int main()
{

    initscr();
    noecho();
    printw("Kolko i krzyzyk");
    try{
        //wiadomość z serwera
        boost::asio::io_service io_service;
        tcp::socket socket(io_service);
        tcp::resolver resolver(io_service);
        tcp::resolver::query query(tcp::v4(), "localhost", "2020");
        tcp::resolver::iterator iterator = resolver.resolve(query);
        boost::asio::connect(socket,iterator);

        boost::array<char, 10> buf;
        boost::system::error_code error;

        Chart chart;

        printw("\nCzy chcesz wczytac stan gry[t/n]?");
        refresh();
        char choice = getch();
        if(choice == 'T' || choice =='t'){
            printw("\nCzekaj na rywala...");
            refresh();
            Frame f;
            f.setType(f.LOAD);
            boost::asio::write(socket,boost::asio::buffer(f.getFrame(),10));
        }else{
            Frame f;
            f.setType(f.BEGIN);
            boost::asio::write(socket,boost::asio::buffer(f.getFrame(),10));
            printw("\nCzekaj na rywala...");
            refresh();
        }
        boost::asio::read(socket,boost::asio::buffer(buf,10));
        Frame f(buf);
        char p_char;
        if(f.getType()==f.LOAD){
            chart.loadChart(f.getChart());
            boost::asio::read(socket,boost::asio::buffer(buf,10));
            Frame f1(buf);
            p_char = f1.getChar();
            chart.setChar(p_char);
        }else{
            p_char = f.getChar();
            chart.setChar(p_char);
            chart.redraw();
        }
        move(1,0);
        clrtoeol();
        move(1,0);
        printw("Grasz %c.",p_char);
        move(8,0);
        printw("Naciskajac odpowiedni klawisz wybierasz pole. Naciskajac 's' zapisujesz stan gry.");


        refresh();
        int c = '0';
        while(c){
            chart.printInfo("Czekaj na swoj ruch");
            boost::asio::read(socket,boost::asio::buffer(buf,10),error);
            //cout << error.message() <<endl;
            chart.printInfo(error.message().c_str());
            chart.printInfo("Twoj ruch");
            refresh();
            Frame f(buf);
            if(f.getChar()!='1')
                chart.markField(f.getChar(),f.getPos());
            switch(f.getType()){
                case f.END:
                    chart.printEnd(f.getWinner());
                    refresh();
                    getch();

                    //because of some errors
                    endwin();
                    exit(1);
                    c = 0;
                    break;
                case f.TURN:
                    while(1){
                        c = getch();
                        if(c >= '1' && c <= '9' && chart.checkField(c-49)){
                            chart.markField(c,p_char);
                            Frame f;
                            f.setMove(f.MOVE,p_char,c);
                            //Wysłanie do serwera informacji o wybranym polu
                            boost::asio::write(socket,boost::asio::buffer(f.getFrame(),10));

                            chart.markField(p_char,c);
                            refresh();
                            break;
                        }else{
                            if(c == 's'){
                                Frame f;
                                f.setType(f.SAVE);
                                boost::asio::write(socket,boost::asio::buffer(f.getFrame(),10));
                                chart.printInfo("Gra zapisana - Twoj ruch");
                            }else
                                chart.printInfo("Zly klawisz ");
                        }
                    }
                    break;
            }
        }
        getch();
    }catch (std::exception& e){
      std::cerr << "Exception: " << e.what() << "\n";
    }
    endwin();
    return 0;
}