Ejemplo n.º 1
0
void BreakableMesh::mergePolygons(int i1, int i2) {
    Polygon p = getPolygon(i1);

    if(!areNeighbours(i1,i2)){
        return;
    }

    std::unordered_map<IndexSegment, int, SegmentHasher> toIgnore;
    swapPolygons(i2, this->polygons.size() - 1, toIgnore);

    Polygon poly1 = getPolygon(i1);
    Polygon poly2 = getPolygon(this->polygons.size() - 1);

    SimplePolygonMerger merger;

    Polygon merged =  merger.mergePolygons(poly1, poly2, points.getList());
    this->polygons[i1] = merged;

    std::vector<IndexSegment> poly2Segments;
    poly2.getSegments(poly2Segments);

    std::unordered_map<Neighbours, int, NeighboursHasher> map;
    Neighbours n(i2, i1);
    map[n] = 0;

    for(IndexSegment s: poly2Segments){
        edges.replace_or_delete(s, this->polygons.size() - 1, i2, i1, map, toIgnore,
                                std::unordered_map<int, int>());
    }

    this->polygons.pop_back();
}
Ejemplo n.º 2
0
void BreakableMesh::swapPolygons(int first, int last, std::unordered_map<IndexSegment,int,SegmentHasher> &toIgnore) {
    Polygon p1 = getPolygon(first);
    Polygon p2 = getPolygon(last);

    std::vector<IndexSegment> firstSegments;
    p1.getSegments(firstSegments);

    std::vector<IndexSegment> lastSegments;
    p2.getSegments(lastSegments);

    for(IndexSegment s: firstSegments){
        auto got = toIgnore.find(s);

        if(got==toIgnore.end()){
            edges.get(s).changeNeighbour(first, last);
        }
    }

    for(IndexSegment s: lastSegments) {
        auto got = toIgnore.find(s);

        if (got == toIgnore.end()) {
            edges.get(s).changeNeighbour(last, first);
        }
    }

    this->polygons[first] = p2;
    this->polygons[last] = p1;
}
Ejemplo n.º 3
0
void BreakableMesh::splitPolygons(NeighbourInfo n1, NeighbourInfo &n2, int init, std::vector<Polygon> &oldPolygons,
                                  std::vector<Polygon> &newPolygons) {
    Polygon& poly1 = getPolygon(n1.neighbour);
    std::vector<int> poly1_points = poly1.getPoints();
    oldPolygons.push_back(poly1);

    //Include new points on the mesh
    int p1 = this->points.push_back(n1.intersection);
    int p2 = this->points.push_back(n2.intersection);

    //Split the old polygon and generate new ones
    std::vector<int> new1 = {p1, p2};
    std::vector<int> new2 = {p2, p1};

    UniqueList<int> newPoints;
    Pair<int> pairs = computeNewPolygons(n1, n2, poly1, newPolygons,
                                         new1, new2, p1, p2, init, -1, -1);

    if(init>=0){
        this->getPolygon(init).insertOnSegment(n1.edge, p1);
    }

    this->getPolygon(n2.neighbour).insertOnSegment(n2.edge, p2);

    // Get the edge information for the old polygon and update it
    if(!n1.isVertex){
        this->edges.delete_element(n1.edge);
    }
    if(!n2.isVertex){
        this->edges.delete_element(n2.edge);
    }

    std::vector<IndexSegment> segments1;
    std::vector<IndexSegment> segments2;

    this->getPolygon(pairs.first).getSegments(segments1);
    this->getPolygon(pairs.second).getSegments(segments2);

    this->edges.insert(IndexSegment(p1,p2),Neighbours(n1.neighbour,n1.neighbour));

    for (int i = 0; i < segments1.size() ; ++i) {
        this->edges.replace_neighbour(segments1[i], n1.neighbour, pairs.first);
    }

    for (int i = 0; i < segments2.size() ; ++i) {
        this->edges.replace_neighbour(segments2[i], n1.neighbour, pairs.second);
    }

    if(!n1.isVertex){
        this->edges.insert_if_null(IndexSegment(p1,n1.edge.getFirst()),init);
        this->edges.insert_if_null(IndexSegment(p1,n1.edge.getSecond()), init);
    }

    if(!n2.isVertex){
        this->edges.insert_if_null(IndexSegment(p2,n2.edge.getFirst()), n2.neighbour);
        this->edges.insert_if_null(IndexSegment(p2,n2.edge.getSecond()), n2.neighbour);
    }

    n2.extraPoint = p2;
}
Ejemplo n.º 4
0
void Controller::dragAnchorPoint(double x, double y){
	if(getPolygon(x,y) != NULL){
		deselectAllPoints();
		getSelectedPoint(x,y)->setSelection(true);
		glfwSetMousePosCallback(MousePosCallback);
	}
}
Ejemplo n.º 5
0
void
GaugeVario::RenderVarioLine(Canvas &canvas, int i, int sink, bool clear)
{
  dirty = true;
  if (i == sink)
    return;

  canvas.Select(clear
                ? look.thick_background_pen
                : (i > sink ? look.thick_lift_pen : look.thick_sink_pen));

  if (i > sink)
    canvas.DrawPolyline(lines + gmax + sink, i - sink);
  else
    canvas.DrawPolyline(lines + gmax + i, sink - i);

  if (!clear) {
    canvas.SelectNullPen();

    // clear up naked (sink) edge of polygon, this gives it a nice
    // taper look
    if (look.inverse) {
      canvas.SelectBlackBrush();
    } else {
      canvas.SelectWhiteBrush();
    }
    canvas.DrawTriangleFan(getPolygon(sink), 3);
  }
}
Ejemplo n.º 6
0
int BreakableMesh::replacePolygonsForMerged(std::vector<int> &polys) {
    std::unordered_map<Neighbours,int,NeighboursHasher> map;
    std::unordered_map<IndexSegment, int,SegmentHasher> toIgnore;
    std::unordered_map<int,int> swappedIndexes;
    std::vector<Pair<int>> pairs;
    fracture_utilities::allPairs(pairs, polys);

    for (Pair<int> p : pairs){
        Neighbours n (p);
        map[n] = 0;
    }

    for (int i = 0; i < polys.size()-1; ++i) {
        int i2 = polys[i];

        swapPolygons(i2, this->polygons.size() - 1, toIgnore);
        swappedIndexes[i2] = this->polygons.size()-1;

        this->printInFile("afterSwapping.txt");
        Polygon poly2 = getPolygon(this->polygons.size() - 1);

        std::vector<IndexSegment> poly2Segments;
        poly2.getSegments(poly2Segments);

        for(IndexSegment s: poly2Segments){
            edges.replace_or_delete(s, this->polygons.size() - 1, i2, polys.back(), map, toIgnore, swappedIndexes);
        }

        this->polygons.pop_back();
        this->printInFile("afterOneDelete.txt");
    }

    return polys.back();
}
Ejemplo n.º 7
0
geos::geom::MultiPolygon* GeoJSONReader::getMultiPolygon(Handle<Value> coords) {

    if (coords->IsArray()) {

        Handle<Array> array = Handle<Array>::Cast(coords);
        uint32_t length = array->Length();
        std::vector<geos::geom::Geometry*>* geoms = new std::vector<geos::geom::Geometry*>();
        try {
            for (uint32_t i = 0; i < length; i++) {
                geos::geom::Polygon* g = getPolygon(array->Get(i));
                geoms->push_back(g);
            }
        }
        catch (...) {
            unsigned size = geoms->size();
            for (unsigned int i = 0; i < size; i++)
                delete (*geoms)[i];
            delete geoms;
            throw;
        }


        return geometryFactory->createMultiPolygon(geoms);
    }


    return geometryFactory->createMultiPolygon();
}
Ejemplo n.º 8
0
void NavMesh::removePolygon(polygon_id id) {
	//todo: don't just use tombstones.
	NavPoly* poly = getPolygon(id);
	//todo: make NavigationPolygon::clear() method
	poly->connections.clear();
	poly->vertex.clear();
	poly->update_centroid();
}
Ejemplo n.º 9
0
std::vector<int> BreakableMesh::getAllPoints(std::vector<int> polys) {
    UniqueList<int> all;
    for (int p : polys) {
        Polygon poly = getPolygon(p);
        all.push_list(poly.getPoints());
    }

    return all.getList();
}
Ejemplo n.º 10
0
bool
TraCIServerAPI_Polygon::getShape(const std::string& id, PositionVector& shape) {
    Polygon* poly = getPolygon(id);
    if (poly == 0) {
        return false;
    }
    shape.push_back(poly->getShape());
    return true;
}
Ejemplo n.º 11
0
void
GaugeVario::RenderNeedle(Canvas &canvas, int i, bool average, bool clear)
{
  dirty = true;

  canvas.SelectNullPen();

  // legacy behaviour
  if (clear ^ look.inverse) {
    canvas.SelectWhiteBrush();
  } else {
    canvas.SelectBlackBrush();
  }

  if (average)
    canvas.DrawPolyline(getPolygon(i), 3);
  else
    canvas.DrawTriangleFan(getPolygon(i), 3);
}
Ejemplo n.º 12
0
	//-----------------------------------------------------------------------
	Polygon::EdgeMap ConvexBody::getSingleEdges() const
	{
		Polygon::EdgeMap edgeMap;

		// put all edges of all polygons into a list every edge has to be
		// walked in each direction once	
		for ( size_t i = 0; i < getPolygonCount(); ++i )
		{
			const Polygon& p = getPolygon( i );

			for ( size_t j = 0; j < p.getVertexCount(); ++j )
			{
				const Vector3& a = p.getVertex( j );
				const Vector3& b = p.getVertex( ( j + 1 ) % p.getVertexCount() );

				edgeMap.insert( Polygon::Edge( a, b ) );
			}
		}

		// search corresponding parts
		Polygon::EdgeMap::iterator it;
		Polygon::EdgeMap::iterator itStart;
		Polygon::EdgeMap::const_iterator itEnd;
		while( !edgeMap.empty() )
		{
			it = edgeMap.begin(); ++it;	// start one element after itStart
			itStart = edgeMap.begin();	// the element to be compared with the others
			itEnd = edgeMap.end();		// beyond the last element
			
			bool bFound = false;

			for ( ; it != itEnd; ++it )
			{
				if (itStart->first.positionEquals(it->second) &&
					 itStart->second.positionEquals(it->first))
				{
					// erase itStart and it
					edgeMap.erase( it );
					edgeMap.erase( itStart );

					bFound = true;

					break; // found
				}
			}

			if ( bFound == false )
			{
				break;	// not all edges could be matched
						// body is not closed
			}
		}

		return edgeMap;
	}
Ejemplo n.º 13
0
	//-----------------------------------------------------------------------
	bool ConvexBody::operator == ( const ConvexBody& rhs ) const
	{
		if ( getPolygonCount() != rhs.getPolygonCount() )
			return false;

		// Compare the polygons. They may not be in correct order.
		// A correct convex body does not have identical polygons in its body.
		bool *bChecked = OGRE_ALLOC_T(bool, getPolygonCount(), MEMCATEGORY_SCENE_CONTROL);
		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			bChecked[ i ] = false;
		}

		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			bool bFound = false;

			for ( size_t j=0; j<getPolygonCount(); ++j )
			{
				const Polygon& pA = getPolygon( i );
				const Polygon& pB = rhs.getPolygon( j );

				if ( pA == pB )
				{
					bFound = true;
					bChecked[ i ] = true;
					break;
				}
			}

			if ( bFound == false )
			{
				OGRE_FREE(bChecked, MEMCATEGORY_SCENE_CONTROL);
				bChecked = 0;
				return false;
			}
		}

		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			if ( bChecked[ i ] != true )
			{
				OGRE_FREE(bChecked, MEMCATEGORY_SCENE_CONTROL);
				bChecked = 0;
				return false;
			}
		}

		OGRE_FREE(bChecked, MEMCATEGORY_SCENE_CONTROL);
		bChecked = 0;
		return true;
	}
Ejemplo n.º 14
0
void defiFill::print(FILE* f) const {
  int i, j;
  struct defiPoints points;

  if (hasLayer())
    fprintf(f, "- LAYER %s", layerName());

  if (layerMask())
      fprintf(f, " + Mask %d", layerMask());

  if (hasLayerOpc())
    fprintf(f, " + OPC");
  fprintf(f, "\n");

  for (i = 0; i < numRectangles(); i++) {
    fprintf(f, "   RECT %d %d %d %d\n", xl(i),
            yl(i), xh(i),
            yh(i));
  }

  for (i = 0; i < numPolygons(); i++) {
    fprintf(f, "   POLYGON ");
    points = getPolygon(i);
    for (j = 0; j < points.numPoints; j++)
      fprintf(f, "%d %d ", points.x[j], points.y[j]);
    fprintf(f, "\n");
  }
  fprintf(f,"\n");

  if (hasVia())
    fprintf(f, "- VIA %s", viaName());

  if (viaTopMask() || viaCutMask() 
      || viaBottomMask()) {
      fprintf(f, " + MASK %d", viaTopMask(),
          viaCutMask(),
          viaBottomMask());
  }

  if (hasViaOpc())
    fprintf(f, " + OPC");
  fprintf(f, "\n");

  for (i = 0; i < numViaPts(); i++) {
    fprintf(f, "   ");
    points = getViaPts(i);
    for (j = 0; j < points.numPoints; j++)
      fprintf(f, "%d %d ", points.x[j], points.y[j]);
    fprintf(f, "\n");
  }
  fprintf(f,"\n");
}
Ejemplo n.º 15
0
	//-----------------------------------------------------------------------
	bool ConvexBody::operator == ( const ConvexBody& rhs ) const
	{
		if ( getPolygonCount() != rhs.getPolygonCount() )
			return false;

		// Compare the polygons. They may not be in correct order.
		// A correct convex body does not have identical polygons in its body.
		bool *bChecked = new bool[ getPolygonCount() ];
		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			bChecked[ i ] = false;
		}

		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			bool bFound = false;

			for ( size_t j=0; j<getPolygonCount(); ++j )
			{
				const Polygon& pA = getPolygon( i );
				const Polygon& pB = rhs.getPolygon( j );

				if ( pA == pB )
				{
					bFound = true;
					bChecked[ i ] = true;
					break;
				}
			}

			if ( bFound == false )
			{
				OGRE_DELETE_ARRAY( bChecked );
				return false;
			}
		}

		for ( size_t i=0; i<getPolygonCount(); ++i )
		{
			if ( bChecked[ i ] != true )
			{
				OGRE_DELETE_ARRAY( bChecked );
				return false;
			}
		}

		OGRE_DELETE_ARRAY( bChecked );
		return true;
	}
Ejemplo n.º 16
0
geos::geom::Geometry* GeoJSONReader::read(Handle<Value> value) {

    if (!value->IsObject()) {
        throw "GeoJSON must be an instance of Object";
    }

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope(isolate);


    Handle<Object> obj = Handle<Object>::Cast(value);

    Handle<String> typeKey = String::NewFromUtf8(isolate, "type");

    if (!obj->HasOwnProperty(typeKey)) {
        throw "Property \"type\" is missing";
    }

    std::string string = *String::Utf8Value(obj->Get(typeKey)->ToString());

    geos::geom::Geometry* g;

    try {
        if (string == "Point") {
            g = getPoint(getCoordsArray(obj));
        } else if (string == "LineString") {
            g = getLineString(getCoordsArray(obj));
        } else if (string == "Polygon") {
            g = getPolygon(getCoordsArray(obj));
        } else if (string == "MultiPoint") {
            g = getMultiPoint(getCoordsArray(obj));
        } else if (string == "MultiLineString") {
            g = getMultiLineString(getCoordsArray(obj));
        } else if (string == "MultiPolygon") {
            g = getMultiPolygon(getCoordsArray(obj));
        } else if (string == "GeometryCollection") {
            g = getGeometryCollection(getGeomsArray(obj));
        }
        else {
            throw "Property \"type\" has a value that is not supported or allowed";
        }
    }
    catch (...) {
        throw;
    }

    return g;
}
Ejemplo n.º 17
0
void MeshBuilder::removePolygon( int index )
{
	Polygon* item = getPolygon(index);
	item->destroy();
	m_this->polygons.remove( index );
	freePolygon( item );

	// update polygon indices
	int i;
	for ( i = index ; i < (int)m_this->polygons.size() ; ++i )
		m_this->polygons[i]->m_index = i;

	// update discontinuous vertex map indices
	for ( i = 0 ; i < discontinuousVertexMaps() ; ++i )
		getDiscontinuousVertexMap(i)->polygonRemoved( index );
}
Ejemplo n.º 18
0
void
GaugeVario::MakePolygon(const int i)
{
  RasterPoint *bit = getPolygon(i);
  RasterPoint *bline = &lines[i + gmax];

  const FastIntegerRotation r(Angle::Degrees(i));

  bit[0] = TransformRotatedPoint(r.Rotate(-offset.x + nlength0, nwidth),
                                 offset);
  bit[1] = TransformRotatedPoint(r.Rotate(-offset.x + nlength1, 0),
                                 offset);
  bit[2] = TransformRotatedPoint(r.Rotate(-offset.x + nlength0, -nwidth),
                                 offset);

  *bline = TransformRotatedPoint(r.Rotate(-offset.x + nline, 0),
                                 offset);
}
Ejemplo n.º 19
0
void MeshBuilder::clear()
{
	removeVertexMaps();
	removeDiscontinuousVertexMaps();

	for ( int index = polygons()-1 ; index >= 0 ; --index )
	{
		Polygon* item = getPolygon( index );
		item->destroy();
		freePolygon( item );
	}
	m_this->polygons.clear();

	for ( int index = vertices()-1 ; index >= 0 ; --index )
	{
		Vertex* item = getVertex( index );
		item->destroy();
		freeVertex( item );
	}
	m_this->vertices.clear();
}
Ejemplo n.º 20
0
Pair<int> BreakableMesh::breakPolygons(NeighbourInfo n1, NeighbourInfo &n2, int init, std::vector<Polygon> &oldPolygons,
                                       std::vector<Polygon> &newPolygons, UniqueList<Pair<int>> &newPoints) {
    Polygon& poly1 = getPolygon(n1.neighbour);
    oldPolygons.push_back(poly1);

    //Include new points on the mesh
    int p1 = this->points.push_back(n1.intersection);
    int p2 = this->points.push_back(n2.intersection);

    int p3;
    if(n1.extraPoint<0){
        p3 = this->points.force_push_back(n1.intersection);
    } else{
        p3 = n1.extraPoint;
    }

    int p4 = this->points.force_push_back(n2.intersection);

    Pair<int> entryPair = Pair<int>(p1, p3);
    Pair<int> exitPair = Pair<int>(p2, p4);

    newPoints.push_back(entryPair);
    newPoints.push_back(exitPair);

    //Split the old polygon and generate new ones
    std::vector<int> new1 = {p1, p2};
    std::vector<int> new2 = {p4, p3};

    Pair<int> pairs = computeNewPolygons(n1, n2, poly1, newPolygons,
                                         new1, new2, p1, p2, init, p3, p4);

    if(init>=0){
        this->getPolygon(init).insertOnSegment(n1.edge, {p3, p1});
        edges.insert(IndexSegment(p1,p3), init);
    }

    this->getPolygon(n2.neighbour).insertOnSegment(n2.edge, {p2, p4});
    edges.insert(IndexSegment(p2,p4), n2.neighbour);

    // Get the edge information for the old polygon and update it
    if(!n1.isVertex){
        this->edges.delete_element(n1.edge);
        if(n1.extraPoint>=0){
            this->edges.delete_element(IndexSegment(p1,p3));
        }
    }
    if(!n2.isVertex){
        this->edges.delete_element(n2.edge);
    }

    std::vector<IndexSegment> segments1;
    std::vector<IndexSegment> segments2;

    this->getPolygon(pairs.first).getSegments(segments1);
    this->getPolygon(pairs.second).getSegments(segments2);

    this->edges.insert(IndexSegment(p1,p2),Neighbours(pairs.first,-1));
    this->edges.insert(IndexSegment(p3,p4),Neighbours(n1.neighbour,-1));

    for (int i = 0; i < segments1.size() ; ++i) {
        this->edges.replace_neighbour(segments1[i], n1.neighbour, pairs.first);
    }

    for (int i = 0; i < segments2.size() ; ++i) {
        this->edges.replace_neighbour(segments2[i], n1.neighbour, pairs.second);
    }

    if(!n1.isVertex){
        this->edges.insert_if_null(IndexSegment(p1, this->getPolygon(pairs.first).getVertex(n1.edge.getFirst(), n1.edge.getSecond())),init);
        this->edges.insert_if_null(IndexSegment(p3, this->getPolygon(pairs.second).getVertex(n1.edge.getFirst(), n1.edge.getSecond())), init);
    }

    if(!n2.isVertex){
        this->edges.insert_if_null(IndexSegment(p2, this->getPolygon(pairs.first).getVertex(n2.edge.getFirst(), n2.edge.getSecond())), n2.neighbour);
        this->edges.insert_if_null(IndexSegment(p4, this->getPolygon(pairs.second).getVertex(n2.edge.getFirst(), n2.edge.getSecond())), n2.neighbour);
    }

    n2.extraPoint = p4;

    return exitPair;
}
Ejemplo n.º 21
0
std::list<utils::Garbage*> GarbageRecognition::garbageList(IplImage * src, IplImage * model){
	std::list<utils::Garbage*>::iterator it;
	for ( it=garbages.begin() ; it != garbages.end() ; it++ )
		delete *it;
	garbages.clear();

	//cvNamedWindow("output",CV_WINDOW_AUTOSIZE);
	//object model

	//image for the histogram-based filter
	//could be a parameter

	utils::Histogram * h = new Histogram(HIST_H_BINS,HIST_S_BINS);
	CvHistogram * testImageHistogram = h->getHShistogramFromRGB(model);

	//~ int frameWidth=cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH);
	//~ int frameHeight=cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT);



	//gets a frame for setting  image size
	//CvSize srcSize = cvSize(frameWidth,frameHeight);
	CvSize srcSize = cvGetSize(src);

	//images for HSV conversion
	IplImage* hsv = cvCreateImage( srcSize, 8, 3 );
	IplImage* h_plane = cvCreateImage( srcSize, 8, 1 );
	IplImage* s_plane = cvCreateImage( srcSize, 8, 1 );
	IplImage* v_plane = cvCreateImage( srcSize, 8, 1 );



	//Image for thresholding
	IplImage * threshImage=cvCreateImage(srcSize,8,1);

	//image for equalization
	IplImage * equalizedImage=cvCreateImage(srcSize,8,1);

	//image for Morphing operations(Dilate-erode)
	IplImage * morphImage=cvCreateImage(srcSize,8,1);

	//image for image smoothing
	IplImage * smoothImage=cvCreateImage(srcSize,8,1);

	//image for contour-finding operations
	IplImage * contourImage=cvCreateImage(srcSize,8,3);

	int frameCounter=1;
	int cont_index=0;

	//convolution kernel for morph operations
	IplConvKernel* element;

	CvRect boundingRect;

	//contours
	CvSeq * contours;

	//Main loop


	frameCounter++;

	//convert image to hsv
	cvCvtColor( src, hsv, CV_BGR2HSV );
	cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );

	//equalize Saturation Channel image
	cvEqualizeHist(s_plane,equalizedImage);

	//threshold the equalized Saturation channel image
	cvThreshold(equalizedImage,threshImage,THRESHOLD_VALUE,255,
	CV_THRESH_BINARY);

	//apply morphologic operations
	element = cvCreateStructuringElementEx( MORPH_KERNEL_SIZE*2+1,
		MORPH_KERNEL_SIZE*2+1, MORPH_KERNEL_SIZE, MORPH_KERNEL_SIZE,
		CV_SHAPE_RECT, NULL);

	cvDilate(threshImage,morphImage,element,MORPH_DILATE_ITER);
	cvErode(morphImage,morphImage,element,MORPH_ERODE_ITER);

	//apply smooth gaussian-filter
	cvSmooth(morphImage,smoothImage,CV_GAUSSIAN,3,0,0,0);

	//get all contours
	contours = myFindContours(smoothImage);

	cont_index=0;
	cvCopy(src,contourImage,0);
	


	while(contours!=NULL){
		CvSeq * aContour=getPolygon(contours);
		utils::Contours * ct = new Contours(aContour);

	
	    int	pf = ct->perimeterFilter(MINCONTOUR_PERIMETER,MAXCONTOUR_PERIMETER);

		int raf = ct->rectangularAspectFilter(CONTOUR_RECTANGULAR_MIN_RATIO, CONTOUR_RECTANGULAR_MAX_RATIO);

		// int af = ct->areaFilter(MINCONTOUR_AREA,MAXCONTOUR_AREA);
		int baf = ct->boxAreaFilter(BOXFILTER_TOLERANCE);

        int hmf = ct->histogramMatchingFilter(src,testImageHistogram, HIST_H_BINS,HIST_S_BINS,HIST_MIN);


		//apply filters

		if( pf && raf && baf && hmf	){

				//if passed filters
				ct->printContour(3,cvScalar(127,127,0,0),
					contourImage);
				
				//get contour bounding box
				boundingRect=cvBoundingRect(ct->getContour(),0);
				cvRectangle(contourImage,cvPoint(boundingRect.x,boundingRect.y),
						cvPoint(boundingRect.x+boundingRect.width,
						boundingRect.y+boundingRect.height),
						_GREEN,1,8,0);
				//build garbage List
			
				//printf(" c %d,%d\n",boundingRect.x,boundingRect.y);

				utils::MinimalBoundingRectangle * r = new utils::MinimalBoundingRectangle(boundingRect.x,
					boundingRect.y,boundingRect.width,boundingRect.height);



				utils::Garbage * aGarbage = new utils::Garbage(r);
//				printf("%d , %d - %d , %d\n",boundingRect.x,boundingRect.y,boundingRect.width,boundingRect.height);

				garbages.push_back(aGarbage);


			}

		delete ct;
		cvReleaseMemStorage( &aContour->storage );
		contours=contours->h_next;
		cont_index++;
	}

   // cvShowImage("output",contourImage);
   // cvWaitKey(0);
	delete h;

	cvReleaseHist(&testImageHistogram);
	//Image for thresholding
	//cvReleaseMemStorage( &contours->storage );
	cvReleaseImage(&threshImage);
	cvReleaseImage(&equalizedImage);
	cvReleaseImage(&morphImage);
	cvReleaseImage(&smoothImage);
	cvReleaseImage(&contourImage);
	
	cvReleaseImage(&hsv);
	cvReleaseImage(&h_plane);
	cvReleaseImage(&s_plane);
	cvReleaseImage(&v_plane);


	return garbages;
}
Ejemplo n.º 22
0
void CBrushPlane::translate(const CVector3 &v){
	getPolygon()->translate(v);
	//getPlane()->translate(v);
}
Ejemplo n.º 23
0
// ===========================================================================
// method definitions
// ===========================================================================
bool
TraCIServerAPI_Polygon::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
                                   tcpip::Storage& outputStorage) {
    // variable & id
    int variable = inputStorage.readUnsignedByte();
    std::string id = inputStorage.readString();
    // check variable
    if (variable != ID_LIST && variable != VAR_TYPE && variable != VAR_COLOR && variable != VAR_SHAPE && variable != VAR_FILL
            && variable != ID_COUNT) {
        return server.writeErrorStatusCmd(CMD_GET_POLYGON_VARIABLE, "Get Polygon Variable: unsupported variable specified", outputStorage);
    }
    // begin response building
    tcpip::Storage tempMsg;
    //  response-code, variableID, objectID
    tempMsg.writeUnsignedByte(RESPONSE_GET_POLYGON_VARIABLE);
    tempMsg.writeUnsignedByte(variable);
    tempMsg.writeString(id);
    // process request
    if (variable == ID_LIST || variable == ID_COUNT) {
        std::vector<std::string> ids;
        ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
        shapeCont.getPolygons().insertIDs(ids);
        if (variable == ID_LIST) {
            tempMsg.writeUnsignedByte(TYPE_STRINGLIST);
            tempMsg.writeStringList(ids);
        } else {
            tempMsg.writeUnsignedByte(TYPE_INTEGER);
            tempMsg.writeInt((int) ids.size());
        }
    } else {
        Polygon* p = getPolygon(id);
        if (p == 0) {
            return server.writeErrorStatusCmd(CMD_GET_POLYGON_VARIABLE, "Polygon '" + id + "' is not known", outputStorage);
        }
        switch (variable) {
            case VAR_TYPE:
                tempMsg.writeUnsignedByte(TYPE_STRING);
                tempMsg.writeString(p->getType());
                break;
            case VAR_COLOR:
                tempMsg.writeUnsignedByte(TYPE_COLOR);
                tempMsg.writeUnsignedByte(p->getColor().red());
                tempMsg.writeUnsignedByte(p->getColor().green());
                tempMsg.writeUnsignedByte(p->getColor().blue());
                tempMsg.writeUnsignedByte(p->getColor().alpha());
                break;
            case VAR_SHAPE:
                tempMsg.writeUnsignedByte(TYPE_POLYGON);
                tempMsg.writeUnsignedByte(MIN2(static_cast<int>(255), static_cast<int>(p->getShape().size())));
                for (unsigned int iPoint = 0; iPoint < MIN2(static_cast<size_t>(255), p->getShape().size()); ++iPoint) {
                    tempMsg.writeDouble(p->getShape()[iPoint].x());
                    tempMsg.writeDouble(p->getShape()[iPoint].y());
                }
                break;
            case VAR_FILL:
                tempMsg.writeUnsignedByte(TYPE_UBYTE);
                tempMsg.writeUnsignedByte(p->getFill() ? 1 : 0);
                break;
            default:
                break;
        }
    }
    server.writeStatusCmd(CMD_GET_POLYGON_VARIABLE, RTYPE_OK, "", outputStorage);
    server.writeResponseWithLength(outputStorage, tempMsg);
    return true;
}
Ejemplo n.º 24
0
PolygonChangeData
BreakableMesh::breakMesh(int init, PointSegment crack, bool initialCrackTip, UniqueList<Pair<int>> &newPoints,
                         std::vector<int> previous, std::vector<int> &createdPolygonIndexes, Polygon &mergedPolygon) {
    std::vector<Polygon> oldPolygons;
    std::vector<Polygon> newPolygons;

    SimplePolygonMerger merger;
    int last = previous.size()==0? -1: (previous[0]==init? previous[1] : previous[0]);
    NeighbourInfo n1 = getNeighbour(init, crack, previous);
    bool firstTime = true;
    Polygon merged;


    if(n1.neighbour<0){
        //If the crack is in one element, return the same element
        return PolygonChangeData(oldPolygons, newPolygons);
    }

    if(initialCrackTip){
        IndexSegment container_edge = this->getPolygon(init).containerEdge(getPoints().getList(), crack.getFirst());
        NeighbourInfo n0 = NeighbourInfo(init, container_edge,crack.getFirst() ,false);
        n0.isVertex = container_edge.isEndPoint(crack.getFirst(), this->points.getList());

        breakPolygons(n0, n1, -1, oldPolygons, newPolygons,
                      newPoints);
        last = this->polygons.size() - 1;
    }


    bool oneLastIteration = false;

    while(true){
        Polygon& poly1 = getPolygon(n1.neighbour);

        if(poly1.containsPoint(this->points.getList(), crack.getSecond())){
            if(poly1.inEdges(this->points.getList(), crack.getSecond())){
                if(!oneLastIteration){
                    oneLastIteration = true;
                }
            }else{
                mergedPolygon = merged;
                return PolygonChangeData(oldPolygons, newPolygons);
            }
        }

        if(firstTime){
            merged = getPolygon(n1.neighbour);
            firstTime = false;
        }else{
            merged = merger.mergePolygons(merged, this->polygons[n1.neighbour], this->points.getList());
        }

        std::vector<int> poly1_points = poly1.getPoints();

        if(!n1.isVertex){
            previous = {init, last};
        }else{
            if(last==-1){
                previous.push_back(last);
            }else{
                previous = {init, last};
            }

        }

        NeighbourInfo n2 = getNeighbour(n1.neighbour, crack, previous);


        if(n1.isEdge){
            init = n1.neighbour;
            n1 = n2;

            continue;
        }

        Pair<int> exit = breakPolygons(n1, n2, init, oldPolygons, newPolygons,
                      newPoints);
        createdPolygonIndexes.push_back(n1.neighbour);
        createdPolygonIndexes.push_back(this->polygons.size()-1);

        // Iterate
        if(oneLastIteration){
            return PolygonChangeData(oldPolygons, newPolygons);
        }

        IndexSegment edge = n2.edge;
        edge.orderCCW(this->points.getList(), merged.getCentroid());
        merged.insertOnSegment(n2.edge, {exit.second, exit.first});

        last = this->polygons.size()-1;
        init = n1.neighbour;
        n1 = n2;

        this->printInFile("afterBreaking.txt");
    }
}
Ejemplo n.º 25
0
bool
TraCIServerAPI_Polygon::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
                                   tcpip::Storage& outputStorage) {
    std::string warning = ""; // additional description for response
    // variable
    int variable = inputStorage.readUnsignedByte();
    if (variable != VAR_TYPE && variable != VAR_COLOR && variable != VAR_SHAPE && variable != VAR_FILL
            && variable != ADD && variable != REMOVE) {
        return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Change Polygon State: unsupported variable specified", outputStorage);
    }
    // id
    std::string id = inputStorage.readString();
    Polygon* p = 0;
    ShapeContainer& shapeCont = MSNet::getInstance()->getShapeContainer();
    if (variable != ADD && variable != REMOVE) {
        p = getPolygon(id);
        if (p == 0) {
            return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Polygon '" + id + "' is not known", outputStorage);
        }
    }
    // process
    switch (variable) {
        case VAR_TYPE: {
            std::string type;
            if (!server.readTypeCheckingString(inputStorage, type)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The type must be given as a string.", outputStorage);
            }
            p->setType(type);
        }
        break;
        case VAR_COLOR: {
            RGBColor col;
            if (!server.readTypeCheckingColor(inputStorage, col)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The color must be given using an according type.", outputStorage);
            }
            p->setColor(col);
        }
        break;
        case VAR_SHAPE: {
            PositionVector shape;
            if (!server.readTypeCheckingPolygon(inputStorage, shape)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The shape must be given using an accoring type.", outputStorage);
            }
            shapeCont.reshapePolygon(id, shape);
        }
        break;
        case VAR_FILL: {
            int value = 0;
            if (!server.readTypeCheckingUnsignedByte(inputStorage, value)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "'fill' must be defined using an unsigned byte.", outputStorage);
            }
            p->setFill(value != 0);
        }
        break;
        case ADD: {
            if (inputStorage.readUnsignedByte() != TYPE_COMPOUND) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "A compound object is needed for setting a new polygon.", outputStorage);
            }
            //readt itemNo
            inputStorage.readInt();
            std::string type;
            if (!server.readTypeCheckingString(inputStorage, type)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The type must be given as a string.", outputStorage);
            }
            RGBColor col;
            if (!server.readTypeCheckingColor(inputStorage, col)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The second polygon parameter must be the color.", outputStorage);
            }
            int value = 0;
            if (!server.readTypeCheckingUnsignedByte(inputStorage, value)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The third polygon parameter must be 'fill' encoded as ubyte.", outputStorage);
            }
            bool fill = value != 0;
            int layer = 0;
            if (!server.readTypeCheckingInt(inputStorage, layer)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The fourth polygon parameter must be the layer encoded as int.", outputStorage);
            }
            PositionVector shape;
            if (!server.readTypeCheckingPolygon(inputStorage, shape)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The fifth polygon parameter must be the shape.", outputStorage);
            }
            //
            if (!shapeCont.addPolygon(id, type, col, (SUMOReal)layer,
                                      Shape::DEFAULT_ANGLE, Shape::DEFAULT_IMG_FILE, shape, fill)) {
                delete p;
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Could not add polygon.", outputStorage);
            }
        }
        break;
        case REMOVE: {
            int layer = 0; // !!! layer not used yet (shouldn't the id be enough?)
            if (!server.readTypeCheckingInt(inputStorage, layer)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "The layer must be given using an int.", outputStorage);
            }
            if (!shapeCont.removePolygon(id)) {
                return server.writeErrorStatusCmd(CMD_SET_POLYGON_VARIABLE, "Could not remove polygon '" + id + "'", outputStorage);
            }
        }
        break;
        default:
            break;
    }
    server.writeStatusCmd(CMD_SET_POLYGON_VARIABLE, RTYPE_OK, warning, outputStorage);
    return true;
}
void getSkels(std::vector<mapping_msgs::PolygonalMap> &pmaps, body_msgs::Skeletons &skels){
   XnUserID aUsers[15];
   XnUInt16 nUsers = 15;
   g_UserGenerator.GetUsers(aUsers, nUsers);
   for (int i = 0; i < nUsers; ++i)
   {
      if (g_bDrawSkeleton && g_UserGenerator.GetSkeletonCap().IsTracking(aUsers[i]))
            {
               body_msgs::Skeleton skel;
               getSkeleton(aUsers[i],skel);
               skels.skeletons.push_back(skel);



               mapping_msgs::PolygonalMap pmap;
               getPolygon(aUsers[i], XN_SKEL_HEAD, XN_SKEL_NECK, pmap);
//               printPt(aUsers[i], XN_SKEL_RIGHT_HAND);
               getPolygon(aUsers[i], XN_SKEL_NECK, XN_SKEL_LEFT_SHOULDER, pmap);
               getPolygon(aUsers[i], XN_SKEL_LEFT_SHOULDER, XN_SKEL_LEFT_ELBOW, pmap);
               getPolygon(aUsers[i], XN_SKEL_LEFT_SHOULDER, XN_SKEL_RIGHT_SHOULDER, pmap);
//               ptdist(pmap.polygons.back());
               getPolygon(aUsers[i], XN_SKEL_LEFT_ELBOW, XN_SKEL_LEFT_HAND, pmap);
               getPolygon(aUsers[i], XN_SKEL_NECK, XN_SKEL_RIGHT_SHOULDER, pmap);
               getPolygon(aUsers[i], XN_SKEL_RIGHT_SHOULDER, XN_SKEL_RIGHT_ELBOW, pmap);
               getPolygon(aUsers[i], XN_SKEL_RIGHT_ELBOW, XN_SKEL_RIGHT_HAND, pmap);
               getPolygon(aUsers[i], XN_SKEL_LEFT_SHOULDER, XN_SKEL_TORSO, pmap);
               getPolygon(aUsers[i], XN_SKEL_RIGHT_SHOULDER, XN_SKEL_TORSO, pmap);
               getPolygon(aUsers[i], XN_SKEL_TORSO, XN_SKEL_LEFT_HIP, pmap);
               getPolygon(aUsers[i], XN_SKEL_LEFT_HIP, XN_SKEL_LEFT_KNEE, pmap);
               getPolygon(aUsers[i], XN_SKEL_LEFT_KNEE, XN_SKEL_LEFT_FOOT, pmap);
               getPolygon(aUsers[i], XN_SKEL_TORSO, XN_SKEL_RIGHT_HIP, pmap);
               getPolygon(aUsers[i], XN_SKEL_RIGHT_HIP, XN_SKEL_RIGHT_KNEE, pmap);
               getPolygon(aUsers[i], XN_SKEL_RIGHT_KNEE, XN_SKEL_RIGHT_FOOT, pmap);
               getPolygon(aUsers[i], XN_SKEL_LEFT_HIP, XN_SKEL_RIGHT_HIP, pmap);
//               getSkel(aUsers[i],pmap);
               pmaps.push_back(pmap);
            }
   }

}
Ejemplo n.º 27
0
std::list<Garbage*>
GarbageRecognition::garbageList(IplImage * src, IplImage * model) {



    std::list<Garbage*> garbageList;

    //cvNamedWindow("output",CV_WINDOW_AUTOSIZE);
    //object model

    //image for the histogram-based filter
    //could be a parameter

    //~ cvNamedWindow("andImage",CV_WINDOW_AUTOSIZE);
    //~ cvNamedWindow("andSimage",CV_WINDOW_AUTOSIZE);
    //~ cvNamedWindow("andSIImage",CV_WINDOW_AUTOSIZE);
    //~ cvNamedWindow("drawContours",CV_WINDOW_AUTOSIZE);
    //~ cvNamedWindow("andSThreshImage",CV_WINDOW_AUTOSIZE);
    //~ cvNamedWindow("threshImage",CV_WINDOW_AUTOSIZE);
//	cvNamedWindow("andSequalizedImage",CV_WINDOW_AUTOSIZE);
    //~ cvNamedWindow("morphImage",CV_WINDOW_AUTOSIZE);

    utils::Histogram * h = new Histogram(HIST_H_BINS,HIST_S_BINS);
    CvHistogram * testImageHistogram = h->getHShistogramFromRGB(model);

    //~ int frameWidth=cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH);
    //~ int frameHeight=cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT);



    //gets a frame for setting  image size
    //CvSize srcSize = cvSize(frameWidth,frameHeight);
    CvSize srcSize = cvGetSize(src);

    //images for HSV conversion
    IplImage* hsv = cvCreateImage( srcSize, 8, 3 );
    IplImage* h_plane = cvCreateImage( srcSize, 8, 1 );
    IplImage* s_plane = cvCreateImage( srcSize, 8, 1 );
    IplImage* v_plane = cvCreateImage( srcSize, 8, 1 );


    //Image for thresholding
    IplImage * andImage=cvCreateImage(srcSize,8,1);

    IplImage * andSimage=cvCreateImage(srcSize,8,1);
    IplImage * andSThreshImage=cvCreateImage(srcSize,8,1);
    IplImage * andSequalizedImage=cvCreateImage(srcSize,8,1);
    IplImage * andSIImage=cvCreateImage(srcSize,8,1);

    //Image for thresholding
    IplImage * threshImage=cvCreateImage(srcSize,8,1);

    //image for equalization
    IplImage * equalizedImage=cvCreateImage(srcSize,8,1);

    //image for Morphing operations(Dilate-erode)
    IplImage * morphImage=cvCreateImage(srcSize,8,1);

    //image for image smoothing
    IplImage * smoothImage=cvCreateImage(srcSize,8,1);

    //image for contour-finding operations
    IplImage * contourImage=cvCreateImage(srcSize,8,3);


    int frameCounter=1;
    int cont_index=0;

    //convolution kernel for morph operations
    IplConvKernel* element;

    CvRect boundingRect;

    //contours
    CvSeq * contours;

    //Main loop


    //convert image to hsv
    cvCvtColor( src, hsv, CV_BGR2HSV );
    cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );


    /*I(x,y)blue ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
    I(x,y)green ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
    I(x,y)red ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]*/

    for(int x=0; x<640; x++) {
        for(int y=0; y<480; y++) {
            uchar * hue=&((uchar*) (h_plane->imageData+h_plane->widthStep*y))[x];
            uchar * sat=&((uchar*) (s_plane->imageData+s_plane->widthStep*y))[x];
            uchar * val=&((uchar*) (v_plane->imageData+v_plane->widthStep*y))[x];
            if((*hue>20 && *hue<40 && *sat>60))
                *hue=255;
            else
                *hue=0;
        }
    }
    cvAnd(h_plane, v_plane, andImage);
    cvAnd(h_plane, s_plane, andSimage);


    //apply morphologic operations
    element = cvCreateStructuringElementEx( MORPH_KERNEL_SIZE*2+1,
                                            MORPH_KERNEL_SIZE*2+1, MORPH_KERNEL_SIZE, MORPH_KERNEL_SIZE,
                                            CV_SHAPE_RECT, NULL);


    cvDilate(andImage,morphImage,element,MORPH_DILATE_ITER);
    cvErode(morphImage,morphImage,element,MORPH_ERODE_ITER);


    cvThreshold(morphImage,threshImage,120,255,CV_THRESH_BINARY);

    //get all contours
    contours=myFindContours(threshImage);
    //contours=myFindContours(smoothImage);


    cont_index=0;

    cvCopy(src,contourImage,0);



    while(contours!=NULL) {

        CvSeq * aContour=getPolygon(contours);
        utils::Contours * ct = new Contours(aContour);




        //apply filters


        if( ct->perimeterFilter(MINCONTOUR_PERIMETER,MAXCONTOUR_PERIMETER) &&
                ct->areaFilter(MINCONTOUR_AREA,MAXCONTOUR_AREA) &&
                //ct->rectangularAspectFilter(CONTOUR_RECTANGULAR_MIN_RATIO, CONTOUR_RECTANGULAR_MAX_RATIO) &&
                ct->boxAreaFilter(BOXFILTER_TOLERANCE) &&
                //ct->histogramMatchingFilter(src,testImageHistogram, HIST_H_BINS,HIST_S_BINS,HIST_MIN)&&
                1) {



            //get contour bounding box
            boundingRect=cvBoundingRect(ct->getContour(),0);
            cvRectangle(contourImage,cvPoint(boundingRect.x,boundingRect.y),
                        cvPoint(boundingRect.x+boundingRect.width,
                                boundingRect.y+boundingRect.height),
                        _GREEN,1,8,0);


            //if passed filters
            ct->printContour(3,cvScalar(127,127,0,0),
                             contourImage);

            std::vector<int> centroid(2);
            centroid=ct->getCentroid();


            //build garbage List
            utils::MinimalBoundingRectangle * r = new utils::MinimalBoundingRectangle(boundingRect.x,
                    boundingRect.y,boundingRect.width,boundingRect.height);

            utils::Garbage * aGarbage = new utils::Garbage(r,centroid);

            garbageList.push_back(aGarbage);


        }

        delete ct;
        cvReleaseMemStorage( &aContour->storage );
        contours=contours->h_next;
        cont_index++;
    }

    cvShowImage("drawContours",contourImage);
    // cvWaitKey(0);
    delete h;


    cvReleaseHist(&testImageHistogram);
    //Image for thresholding
    //cvReleaseMemStorage( &contours->storage );
    cvReleaseImage(&threshImage);
    cvReleaseImage(&equalizedImage);
    cvReleaseImage(&morphImage);
    cvReleaseImage(&smoothImage);
    cvReleaseImage(&contourImage);

    cvReleaseImage(&hsv);
    cvReleaseImage(&h_plane);
    cvReleaseImage(&s_plane);
    cvReleaseImage(&v_plane);
    cvReleaseImage(&andImage);
    cvReleaseImage(&andSimage);
    cvReleaseImage(&andSThreshImage);
    cvReleaseImage(&andSequalizedImage);



    return garbageList;
}
Ejemplo n.º 28
0
void Controller::deletePoint(double x, double y){
	if(getPolygon(x,y) != NULL) getPolygon(x,y)->deletePoint(x,y);
}
Ejemplo n.º 29
0
std::list<Garbage*> 
GarbageRecognition::garbageList(IplImage * src, IplImage * model){

    clock_t start = clock();

                    
	std::list<Garbage*> garbageList;
	std::vector<int> centroid(2);
	
	//~ utils::Histogram * h = new Histogram(HIST_H_BINS,HIST_S_BINS);
	//~ CvHistogram * testImageHistogram = h->getHShistogramFromRGB(model);

	//gets a frame for setting  image size
	CvSize srcSize = cvGetSize(src);
	CvRect srcRect = cvRect(0,0,srcSize.width,srcSize.height);
	
	//images for HSV conversion
	IplImage* hsv = cvCreateImage( srcSize, 8, 3 );
	IplImage* h_plane = cvCreateImage( srcSize, 8, 1 );
	IplImage* h_plane2 = cvCreateImage( srcSize, 8, 1 );
	IplImage* h_planeV ;//= cvCreateImage( srcSize, 8, 1 );
	IplImage* s_plane = cvCreateImage( srcSize, 8, 1 );
	IplImage* v_plane = cvCreateImage( srcSize, 8, 1 );

	//Image for filtering
	IplImage * andImage=cvCreateImage(srcSize,8,1);	
	IplImage * andImageV=cvCreateImage(srcSize,8,1);	
	//Image for thresholding
	IplImage * threshImage=cvCreateImage(srcSize,8,1);
	IplImage * threshImageV=cvCreateImage(srcSize,8,1);

	//image for Morphing operations(Dilate-erode)
	IplImage * morphImage=cvCreateImage(srcSize,8,1);
	IplImage * morphImageV=cvCreateImage(srcSize,8,1);
	
	//image for contour-finding operations
	IplImage * contourImage=cvCreateImage(srcSize,8,3);
	
	clock_t  create=clock();
	printf("Time elapsed create Image: %f\n", ((double)create - start) / CLOCKS_PER_SEC);
	int frameCounter=1;
	int cont_index=0;

	//convolution kernel for morph operations
	IplConvKernel* element;

	CvRect boundingRect;

	//contours
	CvSeq * contours;
	CvSeq * contoursCopy;

	//Main loop


	
	//convert image to hsv
	cvCvtColor( src, hsv, CV_BGR2HSV );
	clock_t  conv=clock();
	printf("Time elapsed create Image- convert image: %f\n", ((double)conv - create) / CLOCKS_PER_SEC);
	
	cvCvtPixToPlane( hsv, h_plane, s_plane, v_plane, 0 );
	h_planeV=cvCloneImage(h_plane);
	h_plane2=cvCloneImage(h_plane);
	
	CvScalar vasosL1 = cvScalar (0, 0, 170);
	CvScalar vasosU1 = cvScalar (20, 255, 255);
	CvScalar vasosL = cvScalar (40, 0, 170);
	CvScalar vasosU = cvScalar (255, 255, 255);
	CvScalar colillasL = cvScalar (20, 60, 0);
	CvScalar colillasU = cvScalar (40, 255,255);

	clock_t  inrange=clock();
	//~ cvInRangeSalt( hsv,vasosL,vasosU, vasosL1, vasosU1,h_plane );
	cvInRangeS( hsv, vasosL1, vasosU1, h_plane );
	cvInRangeS( hsv, vasosL, vasosU, h_plane2 );
	cvOr(h_plane,h_plane2,h_plane);
	printf("inRange  %f\n", ((double)clock() - inrange) / CLOCKS_PER_SEC);

	cvInRangeS( hsv, colillasL,colillasU,h_planeV);
	cvShowImage("inrange vasos",h_plane);
	//~ cvShowImage("inrange colillas",h_planeV);
	//~ for(int x=0;x<srcSize.width;x++){
		//~ for(int y=0;y<srcSize.height;y++){
			//~ uchar * hue=&((uchar*) (h_plane->imageData+h_plane->widthStep*y))[x];
			//~ uchar * hueV=&((uchar*) (h_planeV->imageData+h_plane->widthStep*y))[x];
			//~ uchar * sat=&((uchar*) (s_plane->imageData+s_plane->widthStep*y))[x];
			//~ uchar * val=&((uchar*) (v_plane->imageData+v_plane->widthStep*y))[x];
			
			//~ if((*val>170) && (( (*hue)<20 || (*hue)>40) ))
				//~ *hue=255;
			//~ else
				//~ *hue=0;
			
			//filter for cigar filters
			//~ if((*hueV>20 && *hueV<40 && *sat>60))
				//~ *hueV=255;
			//~ else
				//~ *hueV=0;
		//~ }
	//~ }
	
	clock_t  color=clock();
	printf("Time elapsed create Image - color filter: %f\n", ((double)color - conv) / CLOCKS_PER_SEC);
	
	//--first pipeline
	//apply morphologic operations
	element = cvCreateStructuringElementEx( MORPH_KERNEL_SIZE*2+1,
		MORPH_KERNEL_SIZE*2+1, MORPH_KERNEL_SIZE, MORPH_KERNEL_SIZE,
		CV_SHAPE_RECT, NULL);

	cvDilate(h_plane,morphImage,element,MORPH_DILATE_ITER);
	cvErode(morphImage,morphImage,element,MORPH_ERODE_ITER);
	
	cvThreshold(morphImage,threshImage,100,255,CV_THRESH_BINARY);
	
	clock_t  pipe1=clock();
	printf("Time elapsed color filter - first pipeline: %f\n", ((double)pipe1 - color) / CLOCKS_PER_SEC);
	
	//-- end first pipeline
	//-- start 2nd pipeline-----
	
	cvAnd(h_planeV, v_plane, andImageV);
	//apply morphologic operations

	cvDilate(andImageV,morphImageV,element,MORPH_DILATE_ITER);
	cvErode(morphImageV,morphImageV,element,MORPH_ERODE_ITER);
	
	cvThreshold(morphImageV,threshImageV,100,255,CV_THRESH_BINARY);

    //--end second pipeline--
    clock_t  pipe2=clock();
	printf("Time elapsed first pipeline - second pipeline: %f\n", ((double)pipe2 - pipe1) / CLOCKS_PER_SEC);
	//get all contours
	contours=myFindContours(threshImage);
	contoursCopy=contours;
	
	cont_index=0;
	
	//image to write contours on
	cvCopy(src,contourImage,0);
	
	
	//contours for dishes and glasses
	while(contours!=NULL){

		CvSeq * aContour=getPolygon(contours);
		utils::Contours * ct;
		
		if(this->window==NULL)
			ct = new Contours(aContour);
		else
			ct = new Contours(aContour,this->window->window);
		
		//apply filters for vasos

		if( ct->perimeterFilter(100,10000) && 
			ct->areaFilter(1000,100000) &&
			ct->vasoFilter()
			){	
				//get contour bounding box
				boundingRect=cvBoundingRect(ct->getContour(),0);
				cvRectangle(contourImage,cvPoint(boundingRect.x,boundingRect.y),
						cvPoint(boundingRect.x+boundingRect.width,
						boundingRect.y+boundingRect.height),
						_GREEN,1,8,0);
						
				
				//if passed filters
				ct->printContour(3,cvScalar(127,127,0,0),
					contourImage);
								
				centroid=ct->getCentroid();
				
				//build garbage List
				utils::MinimalBoundingRectangle * r = new utils::MinimalBoundingRectangle(boundingRect.x,
					boundingRect.y,boundingRect.width,boundingRect.height);

				utils::Garbage * aGarbage = new utils::Garbage(r,centroid,ct);
				//benchmark purposes
				aGarbage->isVisualized=true;
				aGarbage->isPredicted=false;
				aGarbage->isFocused=false;
				

				garbageList.push_back(aGarbage);
			}else if( ct->perimeterFilter(100,10000) && 
			ct->areaFilter(1000,100000) &&
			ct->platoFilter()
			){	
				//get contour bounding box
				boundingRect=cvBoundingRect(ct->getContour(),0);
				cvRectangle(contourImage,cvPoint(boundingRect.x,boundingRect.y),
						cvPoint(boundingRect.x+boundingRect.width,
						boundingRect.y+boundingRect.height),
						_GREEN,1,8,0);
							
				//if passed filters
				ct->printContour(3,cvScalar(127,127,0,0),
					contourImage);
								
				centroid=ct->getCentroid();
				
				//build garbage List
				utils::MinimalBoundingRectangle * r = new utils::MinimalBoundingRectangle(boundingRect.x,
					boundingRect.y,boundingRect.width,boundingRect.height);

				utils::Garbage * aGarbage = new utils::Garbage(r,centroid,ct);
				//benchmark purposes
				aGarbage->isVisualized=true;
				aGarbage->isPredicted=false;
				aGarbage->isFocused=false;
				

				garbageList.push_back(aGarbage);
			}

		//delete ct;
		cvReleaseMemStorage( &aContour->storage );
		contours=contours->h_next;
		cont_index++;
	}
	clock_t  vasoyplato=clock();
	printf("Time elapsed first pipe2 - vasos y platos: %f\n", ((double)vasoyplato - pipe2) / CLOCKS_PER_SEC);
	
		//2nd pipeline
		//release temp images and data
		if(contoursCopy!=NULL)
			cvReleaseMemStorage( &contoursCopy->storage );
		
		contours=myFindContours(threshImageV);
		contoursCopy=contours;
		cont_index=0;

		
		while(contours!=NULL){

		CvSeq * aContour=getPolygon(contours);
		utils::Contours * ct;
		
		if(this->window==NULL)
			ct = new Contours(aContour);
		else
			ct = new Contours(aContour,this->window->window);
		
		//apply filters

    
		if( ct->perimeterFilter(10,800) && 
			ct->areaFilter(50,800) &&
			//ct->rectangularAspectFilter(CONTOUR_RECTANGULAR_MIN_RATIO, CONTOUR_RECTANGULAR_MAX_RATIO) && 
			ct->boxAreaFilter(BOXFILTER_TOLERANCE) && 	
			//ct->histogramMatchingFilter(src,testImageHistogram, HIST_H_BINS,HIST_S_BINS,HIST_MIN)&&
			1){	
				//get contour bounding box
				boundingRect=cvBoundingRect(ct->getContour(),0);
				cvRectangle(contourImage,cvPoint(boundingRect.x,boundingRect.y),
						cvPoint(boundingRect.x+boundingRect.width,
						boundingRect.y+boundingRect.height),
						_GREEN,1,8,0);
										
				//if passed filters
				ct->printContour(3,cvScalar(127,127,0,0),
					contourImage);
								
				centroid=ct->getCentroid();
				
				//build garbage List
				utils::MinimalBoundingRectangle * r = new utils::MinimalBoundingRectangle(boundingRect.x,
					boundingRect.y,boundingRect.width,boundingRect.height);

				utils::Garbage * aGarbage = new utils::Garbage(r,centroid,ct);
				//benchmark purposes
				aGarbage->isVisualized=true;
				aGarbage->isPredicted=false;
				aGarbage->isFocused=false;

				garbageList.push_back(aGarbage);
			}

		delete ct;
		cvReleaseMemStorage( &aContour->storage );
		contours=contours->h_next;
		cont_index++;
	}
	clock_t  colillas=clock();
	printf("Time elapsed vasosyplatos - colillas: %f\n", ((double)colillas - vasoyplato) / CLOCKS_PER_SEC);

	//display found contours
    //~ cvShowImage("drawContours",contourImage);
	
	
	//release temp images and data
	if(contoursCopy!=NULL)
		cvReleaseMemStorage( &contoursCopy->storage );
	
	
	cvReleaseStructuringElement(&element);
	cvReleaseImage(&threshImage);
	cvReleaseImage(&threshImageV);
	cvReleaseImage(&morphImage);
	cvReleaseImage(&morphImageV);
	cvReleaseImage(&contourImage);
	cvReleaseImage(&hsv);
	cvReleaseImage(&h_plane);
	cvReleaseImage(&h_planeV);
	cvReleaseImage(&s_plane);
	cvReleaseImage(&v_plane);
	cvReleaseImage(&andImageV);
	cvReleaseImage(&andImage);
	
	clock_t  total=clock();
	printf("total: %f\n", ((double)total - start) / CLOCKS_PER_SEC);
	
	return garbageList;
}