Example #1
0
void
p2t_sweepcontext_init_triangulation (P2tSweepContext *THIS)
{
  guint i;
  double xmax = point_index (THIS->points_, 0)->x, xmin = point_index (THIS->points_, 0)->x;
  double ymax = point_index (THIS->points_, 0)->y, ymin = point_index (THIS->points_, 0)->y;
  double dx, dy;

  /* Calculate bounds. */
  for (i = 0; i < THIS->points_->len; i++)
    {
      P2tPoint* p = point_index (THIS->points_, i);
      if (p->x > xmax)
        xmax = p->x;
      if (p->x < xmin)
        xmin = p->x;
      if (p->y > ymax)
        ymax = p->y;
      if (p->y < ymin)
        ymin = p->y;
    }

  dx = kAlpha * (xmax - xmin);
  dy = kAlpha * (ymax - ymin);
  THIS->head_ = p2t_point_new_dd (xmax + dx, ymin - dy);
  THIS->tail_ = p2t_point_new_dd (xmin - dx, ymin - dy);

  /* Sort points along y-axis */
  g_ptr_array_sort (THIS->points_, p2t_point_cmp);
}
Example #2
0
void
p2t_sweepcontext_init_edges (P2tSweepContext *THIS, P2tPointPtrArray polyline)
{
  int i;
  int num_points = polyline->len;
  g_ptr_array_set_size (THIS->edge_list, THIS->edge_list->len + num_points); /* C-OPTIMIZATION */
  for (i = 0; i < num_points; i++)
    {
      int j = i < num_points - 1 ? i + 1 : 0;
      g_ptr_array_add (THIS->edge_list, p2t_edge_new (point_index (polyline, i), point_index (polyline, j)));
    }
}
Example #3
0
void
p2t_sweepcontext_init (P2tSweepContext* THIS, P2tPointPtrArray polyline)
{
  guint i;

  THIS->front_ = NULL;
  THIS->head_ = NULL;
  THIS->tail_ = NULL;

  THIS->af_head_ = NULL;
  THIS->af_middle_ = NULL;
  THIS->af_tail_ = NULL;

  THIS->edge_list = g_ptr_array_new ();
  THIS->triangles_ = g_ptr_array_new ();
  THIS->map_ = NULL;

  p2t_sweepcontext_basin_init (&THIS->basin);
  p2t_sweepcontext_edgeevent_init (&THIS->edge_event);

  THIS->points_ = g_ptr_array_sized_new (polyline->len);
  for (i = 0; i < polyline->len; i++)
    g_ptr_array_add (THIS->points_, point_index (polyline, i));

  p2t_sweepcontext_init_edges (THIS, THIS->points_);
}
Example #4
0
void
p2t_sweepcontext_add_hole (P2tSweepContext *THIS, P2tPointPtrArray polyline)
{
  guint i;
  p2t_sweepcontext_init_edges (THIS, polyline);
  for (i = 0; i < polyline->len; i++)
    {
      g_ptr_array_add (THIS->points_, point_index (polyline, i));
    }
}
Example #5
0
void
p2t_sweepcontext_create_advancingfront (P2tSweepContext *THIS, P2tNodePtrArray nodes)
{
  /* Initial triangle */
  P2tTriangle* triangle = p2t_triangle_new (point_index (THIS->points_, 0), THIS->tail_, THIS->head_);

  THIS->map_ = g_list_append (THIS->map_, triangle);

  THIS->af_head_ = p2t_node_new_pt_tr (p2t_triangle_get_point (triangle, 1), triangle);
  THIS->af_middle_ = p2t_node_new_pt_tr (p2t_triangle_get_point (triangle, 0), triangle);
  THIS->af_tail_ = p2t_node_new_pt (p2t_triangle_get_point (triangle, 2));
  THIS->front_ = p2t_advancingfront_new (THIS->af_head_, THIS->af_tail_);

  /* TODO: More intuitiv if head is middles next and not previous?
   *       so swap head and tail */
  THIS->af_head_->next = THIS->af_middle_;
  THIS->af_middle_->next = THIS->af_tail_;
  THIS->af_middle_->prev = THIS->af_head_;
  THIS->af_tail_->prev = THIS->af_middle_;
}
void merge_path_operation::merge_inside (svg_path *path, svg_path_geom_iterator dest, svg_path_geom_iterator src)
{
  /// if it is the same subpath, just close it
  if (&dest.subpath () == &src.subpath ())
    {
      auto &elements = dest.subpath ().elements ();
      auto &front_elem = elements.front ();
      auto &back_elem = elements.back ();
      if (elements.size () > 1 && front_elem.point == back_elem.point)
        {
          front_elem.c1 = back_elem.c1;

          svg_path_geom_iterator last_segment_point (*path->get_geom (), dest.get_subpath_index (), dest.subpath ().last_point ());
          size_t point_index = last_segment_point.point_index ();
          path->get_node_type ()->erase (path->get_node_type ()->begin () + point_index);
          elements.pop_back ();
        }
      dest.subpath ().set_closed (true);
      return;
    }

  /// else merge two subpaths

  // if dest is subpath begin, prepend src
  vector<single_path_point> &dest_subpath = dest.subpath ().elements (), &src_subpath = src.subpath ().elements ();
  if (src_subpath.size () > 0)
    {
      svg_path_geom *geom = path->get_geom ();
      auto line_segment = path->get_is_line_segment ();
      auto node_types = path->get_node_type ();
      auto line_begin = line_segment->begin ();
      auto node_type_begin = node_types->begin ();
      int dest_subpath_index = (int)dest.get_subpath_index ();
      int src_subpath_index = (int)src.get_subpath_index ();
      auto src_begin_it = geom->subpath_begin (src_subpath_index);
      auto dst_begin_it = geom->subpath_begin (dest_subpath_index);

      if (dest.get_subpath_point () == 0)
        {
          if (src.get_subpath_point () == 0)
            path->reverse_subpath ((int)src.get_subpath_index ());

          slide (line_begin + src_begin_it.segment_index (cp_type::RIGHT), line_begin + src_begin_it.segment_index (cp_type::RIGHT) + src.subpath ().total_segments (),
                 line_begin + dst_begin_it.segment_index (cp_type::RIGHT));
          slide (node_type_begin + src_begin_it.point_index (), node_type_begin + src_begin_it.point_index () + src.subpath ().total_points (),
                 node_type_begin + dst_begin_it.point_index ());

          node_types->erase (node_type_begin + src_begin_it.point_index () + src.subpath ().total_points () - 1);
          dest_subpath.insert (dest_subpath.begin (), src_subpath.begin (), src_subpath.end () - 1);

        }
      else
        {
          /// reverse src if necessary
          if (src.get_subpath_point () != 0)
            path->reverse_subpath ((int)src.get_subpath_index ());

          slide (line_begin + src_begin_it.segment_index (cp_type::RIGHT), line_begin + src_begin_it.segment_index (cp_type::RIGHT) + src.subpath ().total_segments (),
                 line_begin + dst_begin_it.segment_index (cp_type::RIGHT) + dest.subpath ().total_segments ());

          slide (node_type_begin + src_begin_it.point_index (), node_type_begin + src_begin_it.point_index () + src.subpath ().total_points (),
                 node_type_begin + dst_begin_it.point_index () + dest.subpath ().total_points ());

          node_types->erase (node_type_begin + src_begin_it.point_index ());
          dest_subpath.insert (dest_subpath.end (), src_subpath.begin () + 1, src_subpath.end ());

        }
    }

  auto & subpath = path->get_geom ()->subpath ();
  subpath.erase (subpath.begin () + src.get_subpath_index ());
}
Example #7
0
P2tPoint*
p2t_sweepcontext_get_point (P2tSweepContext *THIS, const int index)
{
  return point_index (THIS->points_, index);
}
Example #8
0
int VtkConditionSource::RequestData( vtkInformation* request,
                                     vtkInformationVector** inputVector,
                                     vtkInformationVector* outputVector )
{
	(void)request;
	(void)inputVector;

	if (this->_points->empty() || this->_cond_vec->empty())
		return 0;

	vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
	vtkSmartPointer<vtkInformation> outInfo = outputVector->GetInformationObject(0);
	vtkSmartPointer<vtkPolyData> output =
	        vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));

	vtkSmartPointer<vtkIdTypeArray> distypes = vtkSmartPointer<vtkIdTypeArray>::New();
	distypes->SetNumberOfComponents(1);
	distypes->SetName("DisTypes");

	vtkSmartPointer<vtkDoubleArray> scalars = vtkSmartPointer<vtkDoubleArray>::New();
	scalars->SetNumberOfComponents(1);
	scalars->SetName("Scalars");
	//std::map<size_t, size_t> idx_map;

	vtkSmartPointer<vtkCellArray> newVerts = vtkSmartPointer<vtkCellArray>::New();
	vtkSmartPointer<vtkCellArray> newLines = vtkSmartPointer<vtkCellArray>::New();
	vtkSmartPointer<vtkCellArray> newPolys = vtkSmartPointer<vtkCellArray>::New();

	if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0)
		return 1;
	/*
	size_t n_pnts = _points->size();
	double value(-9999);
	if (!_cond_vec->empty())
	{
		const std::vector<double> dv = (*_cond_vec)[0]->getDisValue();
		value = dv[dv.size()-1]; // get an existing value for the distribution so scaling on point data will be correct during rendering process!
	}

	for (size_t i = 0; i < n_pnts; i++)
	{
		double coords[3] = {(*(*_points)[i])[0], (*(*_points)[i])[1], (*(*_points)[i])[2]};
		newPoints->InsertNextPoint(coords);
		distypes->InsertNextValue(0);
		scalars->InsertNextValue(value);
	}
	*/
	vtkIdType pnt_id = 0;
	size_t nCond = _cond_vec->size();
	for (size_t n = 0; n < nCond; n++)
	{
		FiniteElement::DistributionType type = (*_cond_vec)[n]->getProcessDistributionType();
		const std::vector<size_t> dis_nodes = (*_cond_vec)[n]->getDisNodes();
		const std::vector<double> dis_values = (*_cond_vec)[n]->getDisValues();

		vtkIdType dis_type_value(0);
		std::map<FiniteElement::DistributionType, vtkIdType>::const_iterator it(_dis_type_map.find(type));
		if (it == _dis_type_map.end())
		{
			dis_type_value = static_cast<vtkIdType>(_dis_type_map.size());
			_dis_type_map.insert(std::pair<FiniteElement::DistributionType, size_t>(type, dis_type_value));
		}
		else dis_type_value = it->second;

		if ((*_cond_vec)[n]->getGeoType() == GeoLib::POINT)
		{
			/*
			size_t nPoints = _points->size();
			const GeoLib::Point* pnt =
			        static_cast<const GeoLib::Point*>((*_cond_vec)[n]->getGeoObj());
			int id(-1);
			for (size_t i = 0; i < nPoints; i++)
				if ((*_points)[i] == pnt)
				{
					id = static_cast<int>(i); //(this->getIndex(i, newPoints, scalars, idx_map));
					vtkIdType vtk_id = static_cast<vtkIdType>(id);
					*/
					const GeoLib::Point* pnt = static_cast<const GeoLib::Point*>((*_cond_vec)[n]->getGeoObj());
					newPoints->InsertNextPoint(pnt->getCoords());

					newVerts->InsertNextCell(1, &pnt_id);
					if (type == FiniteElement::CONSTANT || type == FiniteElement::CONSTANT_NEUMANN)
						scalars->InsertNextValue(dis_values[0]);
					else scalars->InsertNextValue(0);
					distypes->InsertNextValue(dis_type_value);
					pnt_id++;
			/*
					break;
				}
			if (id == -1)
				std::cout <<
				"Error in VtkConditionSource::RequestData() - Point object not found ..."
				          << std::endl;
			*/
		}
		else if ((*_cond_vec)[n]->getGeoType() == GeoLib::POLYLINE)
		{
			const GeoLib::Polyline* ply = static_cast<const GeoLib::Polyline*>((*_cond_vec)[n]->getGeoObj());
			const int nPoints = ply->getNumberOfPoints();
			newLines->InsertNextCell(nPoints);
			double value (0);
			for (int i = 0; i < nPoints; i++)
			{
				size_t point_index = ply->getPointID(i);

				newPoints->InsertNextPoint((*_points)[point_index]->getCoords());
				newLines->InsertCellPoint(pnt_id);
				distypes->InsertNextValue(dis_type_value);

				if (type == FiniteElement::CONSTANT || type == FiniteElement::CONSTANT_NEUMANN)
					scalars->InsertNextValue(dis_values[0]);
				else if (type == FiniteElement::LINEAR || type == FiniteElement::LINEAR_NEUMANN)
				{
					for (size_t j = 0; j < dis_values.size(); j ++)
					{
						if (static_cast<int>(dis_nodes[j]) == i)
							value = dis_values[j];
					}
					scalars->InsertNextValue(value);
				}
				else
					scalars->InsertNextValue(0);
				pnt_id++;
			}
		}
		else if ((*_cond_vec)[n]->getGeoType() == GeoLib::SURFACE)
		{
			std::vector<int> point_idx_map(_points->size(), -1);

			const GeoLib::Surface* sfc =
			        static_cast<const GeoLib::Surface*>((*_cond_vec)[n]->getGeoObj());

			const size_t nTriangles = sfc->getNTriangles();

			for (size_t i = 0; i < nTriangles; i++)
			{
				vtkPolygon* aPolygon = vtkPolygon::New();
				aPolygon->GetPointIds()->SetNumberOfIds(3);

				const GeoLib::Triangle* triangle = (*sfc)[i];
				for (size_t j = 0; j < 3; j++)
				{
					size_t point_index ((*triangle)[j]);

					if (point_idx_map[point_index] == -1)
					{
						point_idx_map[point_index] = pnt_id;
						newPoints->InsertNextPoint((*_points)[point_index]->getCoords());
						aPolygon->GetPointIds()->SetId(j, pnt_id);
						distypes->InsertNextValue(dis_type_value);

						if (type == FiniteElement::CONSTANT || type == FiniteElement::CONSTANT_NEUMANN)
							scalars->InsertNextValue(dis_values[0]);
						else if (type == FiniteElement::LINEAR || type == FiniteElement::LINEAR_NEUMANN)
						{
							for (size_t k = 0; k < dis_values.size(); k++)
								if (static_cast<size_t>(dis_nodes[j]) == point_index)
								{
									scalars->InsertNextValue(dis_values[j]);
									break;
								}
						}
						else scalars->InsertNextValue(0);
						pnt_id++;
					}
					else
						aPolygon->GetPointIds()->SetId(j, static_cast<vtkIdType>(point_idx_map[point_index]));
				}
				newPolys->InsertNextCell(aPolygon);

				aPolygon->Delete();
			}
		}
		// HACK: this is currently used when applying DIRECT conditions
		else if ((*_cond_vec)[n]->getGeoType() == GeoLib::INVALID)
		{
			size_t nValues = dis_values.size();
			for (size_t i=0; i<nValues; i++)
			{
				//vtkIdType pid = newPoints->InsertNextPoint((*_points)[dis_nodes[i]]->getData());
				vtkIdType pid = newPoints->InsertNextPoint((*_points)[i]->getCoords());
				newVerts->InsertNextCell(1, &pid);
				scalars->InsertNextValue(dis_values[i]);
				distypes->InsertNextValue(dis_type_value);
				pnt_id++;
			}
		}
		// draw a bounding box in case of of the conditions is "domain"
		else if ((*_cond_vec)[n]->getGeoType() == GeoLib::GEODOMAIN)
		{
			GeoLib::AABB bounding_box (_points);
			std::vector<GeoLib::Point> box;
			box.push_back(bounding_box.getMinPoint());
			box.push_back(bounding_box.getMaxPoint());

			vtkIdType nPoints = newPoints->GetNumberOfPoints();
			//size_t pnt_idx = _points->size();

			for (size_t i = 0; i < 8; i++)
			{
				double coords[3] =
				{box[i % 2][0], box[(i >> 1) % 2][1], box[i >> 2][2]};
				newPoints->InsertNextPoint(coords);
				distypes->InsertNextValue(dis_type_value);
				scalars->InsertNextValue(0.0);
				//idx_map.insert( std::pair<size_t,size_t>(pnt_idx+i, nPoints+i));
			}

			for (size_t i = 0; i < 4; i++)
			{
				vtkIdType a[2] = {nPoints + i, nPoints + i + 4};
				vtkIdType b[2] = {nPoints + (i * 2), nPoints + (i * 2 + 1)};
				vtkIdType c[2] = {nPoints + (static_cast<int>(i / 2) * 4 + (i % 2)), nPoints + (static_cast<int>(i / 2) * 4 + (i % 2) + 2)};
				newLines->InsertNextCell(2, &a[0]);
				newLines->InsertNextCell(2, &b[0]);
				newLines->InsertNextCell(2, &c[0]);
			}
		}