Beispiel #1
0
	Vectorize::Vectorize(const Image& image) 
				: SourceImage(image), 
				  CurrentImageSplit(image.getWidth(), image.getHeight())
	{
		// line-by-line scan to extract contours of objects
		Point p(0,0);
		for (p.Y = 0; p.Y < SourceImage.getHeight(); p.Y++)
		{
			for (p.X = 0; p.X < SourceImage.getWidth(); p.X++)
			{
				if (SourceImage.isFilled(p))
				{
					if (CurrentImageSplit.getAssignedSegment(p) == NULL)
					{
						Contour* c = new Contour();
						// that pixel is unprocessed yet, so extract the contour starting from it
						c->buildFromImagePart(SourceImage, CurrentImageSplit, p);
						// add new contour
						OuterContours.push_back(c);
					}
					// fixup 'X' scanrow to pass the previously processed contours
					// (null-pointer exception here means that something went totally wrong)
					p = CurrentImageSplit.getAssignedSegment(p)->findRightCorner(p);
				}
			} // for x
		} //for y
	}
Beispiel #2
0
Py::Object TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
{
    Contour::const_iterator line;
    ContourLine::const_iterator point;

    // Find total number of points in all contour lines.
    int n_points = 0;
    for (line = contour.begin(); line != contour.end(); ++line)
        n_points += line->size();

    // Create segs array for point coordinates.
    npy_intp segs_dims[2] = {n_points, 2};
    PyArrayObject* segs = (PyArrayObject*)PyArray_SimpleNew(
                                                2, segs_dims, PyArray_DOUBLE);
    double* segs_ptr = (double*)PyArray_DATA(segs);

    // Create kinds array for code types.
    npy_intp kinds_dims[1] = {n_points};
    PyArrayObject* kinds = (PyArrayObject*)PyArray_SimpleNew(
                                                1, kinds_dims, PyArray_UBYTE);
    unsigned char* kinds_ptr = (unsigned char*)PyArray_DATA(kinds);

    for (line = contour.begin(); line != contour.end(); ++line) {
        for (point = line->begin(); point != line->end(); point++) {
            *segs_ptr++ = point->x;
            *segs_ptr++ = point->y;
            *kinds_ptr++ = (point == line->begin() ? MOVETO : LINETO);
        }
    }

    Py::Tuple result(2);
    result[0] = Py::asObject((PyObject*)segs);
    result[1] = Py::asObject((PyObject*)kinds);
    return result;
}
Beispiel #3
0
	Slice* Mesh::getSlice()
	{
		Slice *s = new Slice();
		Contour *c = new Contour();
		
		while (!segments.empty())
        {
            segIt = segments.begin();
            std::string lbl = static_cast<Point*>(segIt->second->getGeometry(0))->getLabel();
			
            while (segments.count(lbl))
            {				
				//if (lbl.compare("50.79235|15.27517|75.54418") == 0)
//					std::cout << lbl << std::endl;
				Rect *l = segments[lbl];
				c->addGeometry(l);
				segments.erase(segments.find(lbl));
				Point *p2 = static_cast<Point*>(l->getGeometry(1));
				lbl = p2->getLabel();
            }
            c->setInterface(new Graphics(static_cast<GraphicsImp*>(new OpenGLImp())));
			s->addGeometry(c);
			c = new Contour();
        } 
		
		return s;
	}
Beispiel #4
0
void TriContourGenerator::find_boundary_lines(Contour& contour,
                                              const double& level)
{
    // Traverse boundaries to find starting points for all contour lines that
    // intersect the boundaries.  For each starting point found, follow the
    // line to its end before continuing.
    const Triangulation& triang = get_triangulation();
    const Boundaries& boundaries = get_boundaries();
    for (Boundaries::const_iterator it = boundaries.begin();
            it != boundaries.end(); ++it) {
        const Boundary& boundary = *it;
        bool startAbove, endAbove = false;
        for (Boundary::const_iterator itb = boundary.begin();
                itb != boundary.end(); ++itb) {
            if (itb == boundary.begin())
                startAbove = get_z(triang.get_triangle_point(*itb)) >= level;
            else
                startAbove = endAbove;
            endAbove = get_z(triang.get_triangle_point(itb->tri,
                                                       (itb->edge+1)%3)) >= level;
            if (startAbove && !endAbove) {
                // This boundary edge is the start point for a contour line,
                // so follow the line.
                contour.push_back(ContourLine());
                ContourLine& contour_line = contour.back();
                TriEdge tri_edge = *itb;
                follow_interior(contour_line, tri_edge, true, level, false);
            }
        }
    }
}
Beispiel #5
0
bool ContourNode::getValue (const String& strMemberName, String& strValue)
{
    bool bValueSet = false;
    Contour* pObject = dynamic_cast<Contour*>(m_pObject);
    if (strMemberName == L"value")
    {
        ValueObject* pValueObj = dynamic_cast<ValueObject*>(m_pObject);
        if (pValueObj)
        {
            if (!pValueObj->isNothing())
            {
                strValue = pValueObj->toString();
                bValueSet = true;
            }
        }
    }
    else if (strMemberName == L"Elev")
    {
        if (pObject->hasValue_Elev())
        {
            strValue = (DoubleObjectImpl(pObject->getElev())).toString();
            bValueSet = true;
        }
    }
    return bValueSet;
}
Beispiel #6
0
void FeaturesToLabelEngine::OutArea(StyleDef &styleDef, const std::vector<PolygonWithIds> &polygons, const TagMap &tags)
{
	//Transfer area markers and labels to label engine	
	for(size_t j=0; j< styleDef.size(); j++)
	{
		StyleAndLayerDef &styleAndLayerDef = styleDef[j];
		LayerDef &layerDef = styleAndLayerDef.first;
		StyleAttributes &styleAttributes = styleAndLayerDef.second;

		string textName = "";
		TagMap::const_iterator attrIt = styleAttributes.find("text-name");
		if(attrIt != styleAttributes.end()) {
			textName = attrIt->second;
		}
		else
			continue; //Don't draw if name not specified

		//Get average position of outer ways
		for(size_t i=0; i< polygons.size(); i++)
		{
			double px = 0.0, py = 0.0;
			const ContourWithIds &outerWithIds = polygons[i].first;
			for(size_t k=0;k<outerWithIds.size();k++)
			{
				px += outerWithIds[k].second.first;
				py += outerWithIds[k].second.second;
			}
			px /= outerWithIds.size();
			py /= outerWithIds.size();
			Contour shape;
			shape.push_back(Point(px, py));
			poiLabels.push_back(PoiLabel(shape, textName, tags, styleAttributes));
		}
	}
}
Beispiel #7
0
void serializeContour(const Contour& contour,std::vector<int>& out) {
	//for each point in the contour, put it in the blob
	ContourConstIt cursor = contour.begin();
	for(;cursor!=contour.end();cursor++) {
		out.push_back(cursor->x);
		out.push_back(cursor->y);
	}
}
Beispiel #8
0
void ViewPort::DrawEditContour( double pixel_size, double offset_x, double offset_y )
{
	HPEN pen, oldpen;
	HBRUSH brush, oldbrush;
	LOGBRUSH lbrush;
	int oldmode, i, x, y, numpts;
	Contour *c;
	Point *p;
	POINT *lpPoints;

	if ( EditContour && viewDC )
		if ( EditContour->points )
			{
			c = new Contour( *EditContour );				// copy the contour
			
			c->Shift( -offset_x, -offset_y );				// shift into view
			c->Scale( 1.0/pixel_size );						// scale to view's pixels
				
			numpts = c->points->Number();
			lpPoints = new POINT[ numpts ];					// create Window POINT array for drawing

			i = 0;
			p = c->points->first;
			while ( p != NULL )
				{
				lpPoints[i].x = (int)floor(p->x);
				lpPoints[i].y = height - (int)floor(p->y);
				i++;
				p = p->next;
				}
															// create pen for border of object
			pen = CreatePen( PS_DOT, 1, c->border.ref() );
			//pen = CreatePen( PS_SOLID, 1, c->border.ref() );
			oldpen = (HPEN)SelectObject( viewDC, pen );		// set pen into device context

			if ( (c->mode > 0) && c->closed )
				{
				brush = CreateSolidBrush( c->fill.ref() );	// interior will be filled
				oldbrush = (HBRUSH)SelectObject( viewDC, brush );
				SetROP2( viewDC, abs(c->mode) );			// using contour fill mode and color
				Polygon( viewDC, lpPoints, numpts );
				SelectObject( viewDC, oldbrush );			// clean up fill brush
				DeleteObject(brush);
				}

			SelectObject( viewDC, (HBRUSH)GetStockObject(NULL_BRUSH) );	// without coloring interior
			SetROP2( viewDC, R2_COPYPEN );								// draw contour border with pen
			if ( c->closed ) Polygon( viewDC, lpPoints, numpts );
			else Polyline( viewDC, lpPoints, numpts );
			
			SelectObject( viewDC, oldpen );					// clean up pen
			DeleteObject(pen);
			delete[] lpPoints;								// and dynamic memory
			delete c;
			}

}
Beispiel #9
0
GUIButton::GUIButton(const Properties& properties) : mName(properties.mName), mPosition(properties.mPosition),
		mWidth(static_cast<float>(properties.mWidth)),
		mHeight(static_cast<float>(std::max(10u, properties.mHeight))),
		mTextOffset(properties.mTextOffset) {
	
	{ // create and setup the shapes and renderstring the represent the button
		// create the contour that represents both button shapes
		Contour contour;
		contour.AddPoints({glm::vec2(0.0f, 0.0f), glm::vec2(mWidth, 0.0f), glm::vec2(mWidth, mHeight - 10.0f)});
		contour.AddBezier({glm::vec2(mWidth, mHeight - 4.0f), glm::vec2(mWidth - 6.0f, mHeight - 4.0f)});
		contour.AddPoint(glm::vec2(6.0f, mHeight - 4.0f));
		contour.AddBezier({glm::vec2(0.0f, mHeight - 4.0f), glm::vec2(0.0f, mHeight - 10.0f)});
		
		mButtonTop.AddContour(contour);
		mButtonTop.SetOrigin(glm::vec2(0.0f, -2.0f)); // set the offset of the top button to be slightly higher than the base
		mButtonTop.SetColour(properties.mButtonColourTop);
		
		mButtonBottom.AddContour(contour);
		mButtonBottom.SetOrigin(glm::vec2(0.0f, -4.0f));
		mButtonBottom.SetColour(properties.mButtonColourBase);
		
		mButtonText.SetFont(properties.mFont);
		mButtonText.SetText(properties.mText);
		mButtonText.SetSize(properties.mTextSize);
		mButtonText.SetOrigin(glm::vec2(0.0f, -2.0f)); // set the offset of the button text to match the top button
		mButtonText.SetColour(properties.mTextColour);
	}
	
	SetPosition(properties.mPosition); // store the position of the button
	UpdateRenderState(1u); // update the button shapes and render string
	
	if (auto mSharedInputManagerPtr = GUI::mInputManagerPtr.lock()) { // if the input manager pointer is valid...
		// retrieve the current mouse cursor coordinates and update the button state depending on whether they
		// are within the button's bounding box or not
		auto mouseCoords = mSharedInputManagerPtr->GetMouseCoords(CoordinateSpace::Local);
		if (mouseCoords.x > mPosition.x && mouseCoords.x < mPosition.x + mWidth &&
				mouseCoords.y > mPosition.y && mouseCoords.y < mPosition.y + mHeight) {
			
			mInArea = true;
			UpdateRenderState(2u);
		}
	}
	
	{ // serialise the clicked message now as it won't change and we can reuse it
		std::stringstream strStream;
		ClickedMessage msg(mName);
		
		{
			// create an output archive using cereal and our stringstream and serialise the message
			cereal::BinaryOutputArchive archiveOutBinary(strStream);
			archiveOutBinary(msg);
		} // flush the archive on destruction
		
		mMessage = strStream.str(); // store the serialised string
	}
}
// container of connected component
void findBorderEdges( const fwVertexIndex &_vertexIndex , std::vector< std::vector<  std::pair< int, int  > > > &contours)
{
    typedef std::pair< int, int  >  Edge;
    typedef std::vector< Edge > Contour; // at Border
    typedef std::vector< Contour> Contours;

    std::map< Edge  , int > edgesHistogram;
    for ( fwVertexIndex::const_iterator iter=_vertexIndex.begin(); iter!= _vertexIndex.end(); ++iter )
    {
        assert (iter->size()>2 );
        int i1=  (*iter)[0];
        int i2 = (*iter)[1];
        int i3 = (*iter)[2];
        edgesHistogram[std::make_pair(std::min(i1,i2),std::max(i1,i2) )]++;
        edgesHistogram[std::make_pair(std::min(i1,i3),std::max(i1,i3) )]++;
        edgesHistogram[std::make_pair(std::min(i3,i2),std::max(i3,i2) )]++;
    }

    for ( std::map< Edge  , int >::const_iterator iter=edgesHistogram.begin(); iter!=edgesHistogram.end(); ++iter )
    {
        if (iter->second<2) // an orphan found
        {
            Contour contour;
            contour.reserve(1000);
            std::list< Edge > fifo;
            Edge orphan = iter->first;

            fifo.push_back(orphan);
            while( !fifo.empty() )
            {
                Edge current = fifo.front();
                contour.push_back( current );
                fifo.pop_front();
                edgesHistogram[current]=2; // to mark it processed;
                // search neighboor at border and insert in fifo
                for ( std::map< Edge  , int >::const_iterator iterL=edgesHistogram.begin(); iterL!=edgesHistogram.end(); ++iterL )
                {
                    Edge candidate= iterL->first;
                    if ( iterL->second < 2 ) // at border
                    {
                        if ( candidate.first == current.first ||  candidate.second == current.second || // neighboor
                             candidate.first == current.second ||  candidate.second == current.first
                           )
                        {
                            edgesHistogram[candidate]=2; // mark processed;
                            fifo.push_back( candidate );
                        }
                    }
                }
            }
            // all neighboor processed
            contours.push_back( contour );
        }
    }
}
Beispiel #11
0
void on_mouse ( int event, int x, int y, int flags, void* )
{
    if( !img )
        return;

    if( event == CV_EVENT_LBUTTONUP || ! ( flags & CV_EVENT_FLAG_LBUTTON ) ) {
        if( prev_pt.x > 0 )
        {
            cout << "\b\b ";  // Needed! It deletes the last comma
            cout << "]; ";
            cout << " x = A(:,1)'; x = (x-min(x))/800; ";
            cout << " y = A(:,2)'; y = -y+600; y = (y-min(y))/600; ";
            cout << " recognition( feature_extraction(x,y,15), features )\n";

            // using LipiTk
            float res = 0;
            LTKTrace trace;
            for( vector< Point >::iterator iter = current_contour.begin();
                    iter != current_contour.end(); iter++)
            {
                floatVector point;

                point.push_back( iter->x );
                point.push_back( iter->y );

                trace.addPoint(point);
            }
            LTKTraceGroup traceGroup(trace);
            res = shaperectst_recog(traceGroup);

            current_contour.clear();
        }
        prev_pt = cvPoint( -1, -1 );
    }
    else
        if( event == CV_EVENT_MOUSEMOVE && ( flags & CV_EVENT_FLAG_LBUTTON ) ) {
            CvPoint pt = cvPoint( x, y );

            if( prev_pt.x < 0 ) {
                prev_pt = pt;
                cout << " A = [ ";
            }
            else {
                cvLine( img, prev_pt, pt, cvScalarAll ( 255 ), 5, 8, 0 );
            }

            cout << x << " " << y << "; ";
            cout.flush();
            current_contour.push_back ( Point2f ( x, y ) );

            prev_pt = pt;
            imshow( "Blackboard", img );
        }
}
Beispiel #12
0
void Process::findContours()
{
    cvClearMemStorage(contourStorage);
    contours.clear();

    cvCvtColor(image, grayImage, CV_RGB2GRAY);

//    if (param.contour.smooth) {
//        cvSmooth(grayImage, grayImage, CV_BLUR, 3, 3);
//    }

    cvCanny(grayImage, hitImage, contourParam.threshold1, contourParam.threshold2, 3);

    // находим контуры
    cvFindContours(hitImage, contourStorage, &contoursSeq, sizeof(CvContour),
                   CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));

    for(CvSeq* seq = contoursSeq; seq != 0; seq = seq->h_next) {
        Contour contour;
        for( int i=0; i<seq->total; ++i ) {
            CvPoint* cvP = (CvPoint*)cvGetSeqElem(seq, i);
            ContourPt pt;
            pt.x = cvP->x;
            pt.y = cvP->y;
            contour.push_back(pt);
            //qDebug() << cvP->x << cvP->y;
        }
        contours.push_back(contour);
    }

    // пример работы с контуром
    //for(CvSeq* seq = contours; seq != 0; seq = seq->h_next){
        // нарисовать контур
        // cvDrawContours(dstImage, seq, CV_RGB(255,216,0), CV_RGB(0,0,250), 0, 1, 8);
        // Работаем с точками последовательности
         //CvPoint* p = (CvPoint*)cvGetSeqElem ( seq, i );
    //}

    // рисуем обводку
//    if (param.contour.isDrawHull) {
//        CvMemStorage* hullStorage = cvCreateMemStorage(0);

//        for(CvSeq* seq = contours; seq != 0; seq = seq->h_next){
//            CvSeq *hulls = cvConvexHull2(seq, hullStorage, CV_CLOCKWISE, 1);
//            //cvDrawContours(dstImage, hulls, CV_RGB(255, 0, 0), CV_RGB(100, 0, 0), 0, 2, 8);

//            cvClearMemStorage(hullStorage);
//        }

//        cvReleaseMemStorage(&hullStorage);
    //    }

}
Beispiel #13
0
Shape & Shape::lineTo(const glm::vec3 & p)
{
	// Start if their is no current
	if (!getCurrent())
		moveTo(glm::vec3(0, 0, 0));

	// Add Line
	Contour * current = getCurrent();
	if (current)
		current->lineTo(glm::dvec3(p));

	return *this;
}
Beispiel #14
0
void deSerializeContour(const std::vector<int>& in,Contour& out) {
	out.clear();
	//for each point in the contour, put it in the blob
	std::vector<int>::const_iterator cursor = in.begin();
	assert(in.size()%2==0);
	for(;cursor!=in.end();) {
		cv::Point pt(*(cursor++),*(cursor++));
		int temp = pt.x;
		pt.x = pt.y;
		pt.y=temp;
		out.push_back(pt);
	}
}
Beispiel #15
0
void Triangulator::build_path(const Contour &contour, Path &path, int index_offset) {
	// TODO: connect multiple contours
	path.clear();
	path.resize(contour.get_chunks().size());
	for(int i = 0; i < (int)contour.get_chunks().size(); ++i) {
		const Contour::Chunk &c = contour.get_chunks()[i];
		Vertex &v = path[i];
		v.index = i + index_offset;
		v.p = c.p1;
		v.next = &v + 1;
	}
	path.back().next = &path.front();
}
Beispiel #16
0
void
Hexagon::odbOutputLayerFeature(
    OdbFeatureFile& file, QString polarity,
    QPointF location, Xform *xform)
{
  Contour surface;
  QPointF p(0, 0.5 * m_length.inch());
  surface.polygon().setPolyBegin(p);
  for (int i = 0; i < 6; ++i) {
    p = rotatePoint(p, 60);
    surface.polygon().addSegment(p);
  }
  surface.odbOutputLayerFeature(file, polarity, location, xform);
}
Beispiel #17
0
Shape & Shape::moveTo(const glm::vec3 & p)
{
	Contour c(p);

	// Close Current Contour
	Contour * current = getCurrent();
	if (current)
		current->close();

	// Add new Contour
	_contours.push_back(std::move(c));

	return *this;
}
Beispiel #18
0
Plane OpenCVContourMatcher::compareBruteForce(Contour contour1, Contour contour2){
	//Convert from contour class to matrix
	cv::Mat c1 = sliceContour(contour1.getContourBoundary(),image1);
	cv::Mat c2 = sliceContour(contour2.getContourBoundary(),image2);
	// Detect feature points of contour 1 and contour 2
	std::vector<cv::KeyPoint> feat1 = detectFeaturePoints(c1);
	std::vector<cv::KeyPoint> feat2 = detectFeaturePoints(c2);
	// Extract feature descriptors
	cv::Mat desc1 = extractDescriptors(c1,feat1);
	cv::Mat desc2 = extractDescriptors(c2,feat2);
	// Match feature descriptors and refine matches then return as vector of PixelLocations
	std::vector<cv::DMatch> matches = matchBruteForce(desc1,desc2);
	Plane planePoints = convertDMatchesToPlane(feat1,feat2,refineMatches(matches));
	return planePoints;
}
bool mitk::CorrectorTool2D::OnMouseMoved   (Action* action, const StateEvent* stateEvent)
{
  if (!FeedbackContourTool::OnMouseMoved( action, stateEvent )) return false;

  const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return false;

  Contour* contour = FeedbackContourTool::GetFeedbackContour();
  contour->AddVertex( positionEvent->GetWorldPosition() );

  assert( positionEvent->GetSender()->GetRenderWindow() );
  mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );

  return true;
}
bool mitk::CorrectorTool2D::OnMousePressed (Action* action, const StateEvent* stateEvent)
{
  if (!FeedbackContourTool::OnMousePressed( action, stateEvent )) return false;

  const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return false;

  Contour* contour = FeedbackContourTool::GetFeedbackContour();
  contour->Initialize();
  contour->AddVertex( positionEvent->GetWorldPosition() );
  
  FeedbackContourTool::SetFeedbackContourVisible(true);

  return true;
}
/*******************************************************************
 * Function Name: Offset
 * Return Type 	: const CarryContour
 * Created On	: Mar 17, 2014
 * Created By 	: hrushi
 * Comments		: offsets the contour with respect to the given point
 * Arguments	: const cv::Point Pt
 *******************************************************************/
const Contour Contour::Offset( const cv::Point Pt) const
{
	Contour Ctr = *this;

	vector<ImagePt> OffSetPts = ContourPoints;

	for(UINT i = 0; i < OffSetPts.size(); i++)
	{
		OffSetPts.at(i) = OffSetPts.at(i) +  Pt;
	}

	Ctr.SetCtrPoints(OffSetPts);
	Ctr.CalculateCntrParam();

	return Ctr;
}
Beispiel #22
0
bool Contour::equals(Contour c)
{
    if(c.getLabel() == label)
        return true;

    return false;
}
Beispiel #23
0
    Contour Contour::autoCorrelate() const {
        Contour res;
        double maxNorm = 0;
        res.reserve(size() / 2);

        for (unsigned int i = 0; i < size() / 2; i++) {
            auto const& dot = dotProduct(*this, i);
            res.push_back(dot);
            maxNorm = std::max(maxNorm, ::pow(dot.real(), 2) + ::pow(dot.imag(), 2));
        }
        maxNorm = ::sqrt(maxNorm);

        for (auto value : res) {
            value /= maxNorm;
       }
        return res;
    }
Beispiel #24
0
Py::Object TriContourGenerator::contour_to_segs(const Contour& contour)
{
    Py::List segs(contour.size());
    for (Contour::size_type i = 0; i < contour.size(); ++i) {
        const ContourLine& line = contour[i];
        npy_intp dims[2] = {static_cast<npy_intp>(line.size()),2};
        PyArrayObject* py_line = (PyArrayObject*)PyArray_SimpleNew(
                                                     2, dims, PyArray_DOUBLE);
        double* p = (double*)PyArray_DATA(py_line);
        for (ContourLine::const_iterator it = line.begin(); it != line.end(); ++it) {
            *p++ = it->x;
            *p++ = it->y;
        }
        segs[i] = Py::asObject((PyObject*)py_line);
    }
    return segs;
}
bool CollisionOutline_Impl::point_inside_contour( const Pointf &point, const Contour &contour )
{
	// In case the contour is inside-out (the inside of a hollow polygon) it makes no sense to do this test.
	if(contour.is_inside_contour())
		return false;
	
	LineSegment2f lineX( Pointf(point.x, point.y+0.000f), Pointf(point.x+99999.0f, point.y+0.000f) );

	// collide the line with the outline.
	int num_intersections_x = 0;

	const std::vector<Pointf> &points = contour.get_points();

	std::vector<OutlineCircle>::const_iterator it;
	for( it = contour.get_sub_circles().begin();
		 it != contour.get_sub_circles().end();
		 ++it )
	{
		const OutlineCircle &circle = (*it);

		float dist = fabs(circle.position.y - point.y);

		if( dist <= circle.radius )
		{
			// test each line segment inside the circle
		
			for( unsigned int i=circle.start; i != circle.end; ++i )
			{
				LineSegment2f line2(points[ i    % points.size()], points[(i+1) % points.size()]);

				if( lineX.intersects(line2, false) )
				{
					num_intersections_x++;
				}
			}
		}
	}

	if( num_intersections_x % 2 )
	{
		return true;
	}
	
	return false;
}
void ContourDistancesHistogram::construct( const Contour &contour, const iCoord2D &pithCoord )
{
	clear();

	const int nbPoints = contour.size();
	if ( nbPoints > 0 )
	{
		this->resize(nbPoints);

		QVector<qreal>::Iterator thisIterator = this->begin();
		QVector<iCoord2D>::ConstIterator contourIterator = contour.begin();
		const QVector<iCoord2D>::ConstIterator endContour = contour.end();
		while ( contourIterator != endContour )
		{
			*thisIterator++ = (*contourIterator++).euclideanDistance(pithCoord);
		}
	}
}
Beispiel #27
0
    double Contour::diffR2(const Contour& c) {
#ifndef NDEBUG
        assert(size() == c.size());
#endif

        double maxNorm = 0;
        double diffSum = 0;
        double v1;
        double v2;
        for (unsigned int i = 0; i < size(); i++) {
            v1 = std::norm(at(i));
            v2 = std::norm(c.at(i));
            maxNorm = std::max(maxNorm, v1);
            maxNorm = std::max(maxNorm, v2);
            diffSum += ::pow(v1 - v2, 2);
        }
        return 1 - diffSum / size() / ::sqrt(maxNorm);
    }
Beispiel #28
0
bool ContourNode::setValue (const String& strMemberName, const String* pstrValue)
{
    bool bValueSet = false;
    Contour* pObject = dynamic_cast<Contour*>(m_pObject);
    if (strMemberName == L"Elev")
    {
        if (!pstrValue)
        {
            pObject->resetValue_Elev();
        }
        else
        {
            pObject->setElev(DoubleObjectImpl::parseString(pstrValue->c_str(), pstrValue->length()));
            bValueSet = true;
        }
    }
    return bValueSet;
}
Beispiel #29
0
bool Contour::operator<( const Contour& other ) const {
    bool lessThan = false;
    double thisLevel = getLevel();
    double otherLevel = other.getLevel();
    if ( thisLevel < otherLevel && qAbs( thisLevel - otherLevel) > ERROR_MARGIN ){
        lessThan = true;
    }
    return lessThan;
}
Beispiel #30
0
bool mitk::CorrectorTool2D::OnMousePressed (Action* action, const StateEvent* stateEvent)
{
  const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent());
  if (!positionEvent) return false;

  m_LastEventSender = positionEvent->GetSender();
  m_LastEventSlice = m_LastEventSender->GetSlice();

  if ( FeedbackContourTool::CanHandleEvent(stateEvent) < 1.0 ) return false;

  Contour* contour = FeedbackContourTool::GetFeedbackContour();
  contour->Initialize();
  contour->AddVertex( positionEvent->GetWorldPosition() );
  
  FeedbackContourTool::SetFeedbackContourVisible(true);

  return true;
}