Пример #1
0
bool ShortcutPath(
    const PathContainer&            points,
    const CostsContainer&           costs,
    const PathGeneratorsContainer&  generators,
    ShortcutPathContainer&          shortcut_points,
    size_t                          window,
    size_t                          granularity,
    const CostCompare&              leq)
{
    typedef typename PathContainer::value_type Point;
    typedef typename CostsContainer::value_type Cost;
    typedef typename PathGeneratorsContainer::value_type PathGenerator;
    typedef typename std::back_insert_iterator<ShortcutPathContainer> OutputIt;

    typedef CallablePathGenerator<Point, Cost, PathGenerator, OutputIt>
    CallablePathGeneratorType;

    std::vector<CallablePathGeneratorType> gens;
    for (const auto& gen : generators) {
        gens.push_back(CallablePathGeneratorType(gen));
    }

    return ShortcutPath(
            points.begin(), points.end(),
            costs.begin(), costs.end(),
            gens.begin(), gens.end(),
            std::back_inserter(shortcut_points),
            window,
            granularity,
            leq);
}
Пример #2
0
static void read_images(const PathContainer& paths, ImageContainer& imgs) {
	typedef typename PathContainer::const_iterator pc_iter;
	typedef typename ImageContainer::value_type img_t;

	for(pc_iter it = paths.begin(); it != paths.end(); ++it) {
		imgs.push_back( img_t() );
		MAGICK_WRAP( ImOp::read(*it).call(imgs.back()) );
	}
}
 void filter(PathContainer& paths) {
     for (PathContainer::Iterator iter = paths.begin(); iter != paths.end(); ) {
         if (!conjugateOperator(predicate(*iter.get()), predicate(*iter.getConjugate()))) {
             iter = paths.erase(iter);
         }
         else {
             ++iter;
         }
     }
 }
    void ConstructFASTG(PathContainer& paths,
            map<BidirectionalPath*, string >& ids,
            map<BidirectionalPath*, set<string> >& next_ids) const {

        MakeIDS(paths, ids, next_ids);

        map<VertexId, set<BidirectionalPath*> > v_starting;
        map<EdgeId, set<BidirectionalPath*> > e_starting;
        //set<VertexId> visited;
        //queue<BidirectionalPath*> path_queue;
        FindPathsOrder(paths, v_starting, e_starting);

        for (auto iter = paths.begin(); iter != paths.end(); ++iter) {
            if (iter.get()->Size() == 0)
                continue;

            BidirectionalPath* path = iter.get();
            EdgeId e = path->Back();
            VertexId v = g_.EdgeEnd(e);
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: v_starting[v]) {
                TRACE(ids[next_path]);
                next_ids[path].insert(ids[next_path]);
            }
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: e_starting[e]) {
                TRACE(ids[next_path]);
                next_ids[path].insert(ids[next_path]);
            }

            path = iter.getConjugate();
            e = path->Back();
            v = g_.EdgeEnd(e);
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: v_starting[v]) {
                TRACE(ids[next_path]);
                next_ids[path].insert(ids[next_path]);
            }
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: e_starting[e]) {
                TRACE(ids[next_path]);
                next_ids[path].insert(ids[next_path]);
            }
        }

        VerifyIDS(paths, ids, next_ids, v_starting, e_starting);
    }
    void MakeIDS(PathContainer& paths,
                 map<BidirectionalPath*, string >& ids,
                 map<BidirectionalPath*, set<string> >& next_ids) const {
        int counter = 1;
        for (auto iter = paths.begin(); iter != paths.end(); ++iter) {
            if (iter.get()->Size() == 0)
                continue;

            BidirectionalPath* p = iter.get();
            BidirectionalPath* cp = iter.getConjugate();
            string name = io::MakeContigId(counter++, p->Length() + k_, p->Coverage(), p->GetId());
            ids.insert(make_pair(p, name));
            ids.insert(make_pair(cp, name + "'"));
            next_ids.insert(make_pair(p, set<string>()));
            next_ids.insert(make_pair(cp, set<string>()));
        }
    }
    void VerifyIDS(PathContainer& paths,
                 map<BidirectionalPath*, string >& ids,
                 map<BidirectionalPath*, set<string> >& next_ids,
                 map<VertexId, set<BidirectionalPath*> >& v_starting,
                 map<EdgeId, set<BidirectionalPath*> >& e_starting) const {

        for (auto iter = paths.begin(); iter != paths.end(); ++iter) {
            BidirectionalPath* path = iter.get();
            if (path->Size() == 0)
                continue;

            EdgeId e = path->Back();
            VertexId v = g_.EdgeEnd(e);
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: v_starting[v]) {
                TRACE("Vertex: " << ids[next_path]);
                auto it = next_ids[path].find(ids[next_path]);
                VERIFY(it != next_ids[path].end());
            }
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: e_starting[e]) {
                TRACE("Edge: " << ids[next_path]);
                auto it = next_ids[path].find(ids[next_path]);
                VERIFY(it != next_ids[path].end());
            }

            path = iter.getConjugate();
            e = path->Back();
            v = g_.EdgeEnd(e);
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: v_starting[v]) {
                TRACE("Vertex: " << ids[next_path]);
                auto it = next_ids[path].find(ids[next_path]);
                VERIFY(it != next_ids[path].end());
            }
            TRACE("Node " << ids[path] << " is followed by: ");
            for (BidirectionalPath* next_path: e_starting[e]) {
                TRACE("Edge: " << ids[next_path]);
                auto it = next_ids[path].find(ids[next_path]);
                VERIFY(it != next_ids[path].end());
            }
        }
    }
    void FindPathsOrder(PathContainer& paths,
                        map<VertexId, set<BidirectionalPath*> >& v_starting,
                        map<EdgeId, set<BidirectionalPath*> >& e_starting) const {
        for (auto iter = paths.begin(); iter != paths.end(); ++iter) {
            if (iter.get()->Size() == 0)
                continue;

            BidirectionalPath* path = iter.get();
            DEBUG(g_.int_id(g_.EdgeStart(path->Front())) << " -> " << path->Size() << ", " << path->Length());
            EdgeId e = path->Front();
            VertexId v = g_.EdgeStart(e);
            if (v_starting.count(v) == 0) {
                v_starting.insert(make_pair(v, set<BidirectionalPath*>()));
            }
            v_starting[v].insert(path);
            if (path->Size() > 1) {
                if (e_starting.count(e) == 0) {
                    e_starting.insert(make_pair(e, set<BidirectionalPath*>()));
                }
                e_starting[e].insert(path);
            }

            path = iter.getConjugate();
            DEBUG(g_.int_id(g_.EdgeStart(path->Front())) << " -> " << path->Size() << ", " << path->Length());
            e = path->Front();
            v = g_.EdgeStart(e);
            if (v_starting.count(v) == 0) {
                v_starting.insert(make_pair(v, set<BidirectionalPath*>()));
            }
            v_starting[v].insert(path);
            if (path->Size() > 1) {
                if (e_starting.count(e) == 0) {
                    e_starting.insert(make_pair(e, set<BidirectionalPath*>()));
                }
                e_starting[e].insert(path);
            }
        }
    }
Пример #8
0
static void convert_to_KTEX(const PathContainer& input_paths, const string& output_path, const KTEX::File::Header& h) {
	typedef typename PathContainer::const_iterator pc_iter;
	typedef std::vector<Magick::Image> image_container_t;
	typedef image_container_t::iterator image_iterator_t;

	const int verbosity = options::verbosity;

	if(input_paths.size() > 1 && should_resize()) {
		throw Error("Attempt to resize a mipchain.");
	}

	assert( !input_paths.empty() );

	if(verbosity >= 0) {
		cout << "Loading non-TEX from `" << input_paths.front() << "'";

		size_t count = 1;
		for(pc_iter it = ++input_paths.begin(); it != input_paths.end(); ++it, ++count) {
			cout << ", `" << *it << "'";
			if(count > 4 && verbosity < 3) {
				cout << ", [...]";
				break;
			}
		}
		cout << "." << endl;
	}
	image_container_t imgs;
	if(input_paths.size() > 1) {
		imgs.reserve( input_paths.size() );
	}
	read_images( input_paths, imgs );
	assert( input_paths.size() == imgs.size() );

	KTEX::File tex;
	ImOp::ktexCompressor(h, std::min(options::verbosity, 0)).compress( tex, imgs );
	tex.dumpTo(output_path, verbosity);
}
Пример #9
0
            void BooleanGenerator::AddToTriangleBuffer(TriangleBuffer& Buffer) const
            {
                const VertexContainer& Vertices1 = this->FirstBuffer->GetVertices();
                const IndexContainer& Indexes1 = this->FirstBuffer->GetIndices();
                const VertexContainer& Vertices2 = this->SecondBuffer->GetVertices();
                const IndexContainer& Indexes2 = this->SecondBuffer->GetIndices();

                LineSegment3D IntersectionResult;
                IntersectContainer IntersectionList;

                // Find all intersections between FirstBuffer and SecondBuffer
                Integer FirstIndex = 0;
                for( IndexContainer::const_iterator FirstBufferIt = Indexes1.begin() ; FirstBufferIt != Indexes1.end() ; FirstIndex++ )
                {
                    Triangle3D Tri1( Vertices1[ *FirstBufferIt++ ].Position, Vertices1[ *FirstBufferIt++ ].Position, Vertices1[ *FirstBufferIt++ ].Position );

                    Integer SecondIndex = 0;
                    for( IndexContainer::const_iterator SecondBufferIt = Indexes2.begin() ; SecondBufferIt != Indexes2.end() ; SecondIndex++ )
                    {
                        Triangle3D Tri2( Vertices2[ *SecondBufferIt++ ].Position, Vertices2[ *SecondBufferIt++ ].Position, Vertices2[ *SecondBufferIt++ ].Position );

                        IntersectionResult = Tri1.GetOverlap(Tri2);
                        if( IntersectionResult.PointA != IntersectionResult.PointB ) {
                            Intersect Inter(IntersectionResult,FirstIndex,SecondIndex);
                            IntersectionList.push_back(Inter);
                        }
                    }
                }
                // Remove all intersection segments too small to be relevant
                for( IntersectContainer::iterator InterIt = IntersectionList.begin() ; InterIt != IntersectionList.end() ;  )
                {
                    if( ( InterIt->Segment.PointB - InterIt->Segment.PointA ).SquaredLength() < 1e-8 ) {
                        InterIt = IntersectionList.erase(InterIt);
                    }else{
                        ++InterIt;
                    }
                }

                // Retriangulate
                TriangleBuffer NewMesh1, NewMesh2;
                _Retriangulate(NewMesh1,*(this->FirstBuffer),IntersectionList,true);
                _Retriangulate(NewMesh2,*(this->SecondBuffer),IntersectionList,false);

                //Buffer.append(NewMesh1);
                //Buffer.append(NewMesh2);
                //return;

                // Trace contours
                PathContainer Contours;
                LineSeg3DVec SegmentSoup;
                for( IntersectContainer::iterator InterIt = IntersectionList.begin() ; InterIt != IntersectionList.end() ; ++InterIt )
                    { SegmentSoup.push_back( InterIt->Segment ); }
                Path::BuildFromSegmentSoup(SegmentSoup,Contours);

                // Build a lookup from segment to triangle
                TriLookup TriLookup1, TriLookup2;
                _BuildTriLookup( TriLookup1, NewMesh1 );
                _BuildTriLookup( TriLookup2, NewMesh2 );

                LineSeg3DSet Limits;
                for( LineSeg3DVec::iterator SegSoupIt = SegmentSoup.begin() ; SegSoupIt != SegmentSoup.end() ; ++SegSoupIt )
                    { Limits.insert( SegSoupIt->GetOrderedCopy() ); }
                // Build resulting mesh
                for( PathContainer::iterator PathIt = Contours.begin() ; PathIt != Contours.end() ; ++PathIt )
                {
                    // Find 2 seed triangles for each contour
                    LineSegment3D FirstSeg( PathIt->GetPoint(0), PathIt->GetPoint(1) );

                    TriLookupRange It2mesh1 = TriLookup1.equal_range( FirstSeg.GetOrderedCopy() );
                    TriLookupRange It2mesh2 = TriLookup2.equal_range( FirstSeg.GetOrderedCopy() );
                    Integer Mesh1Seed1, Mesh1Seed2, Mesh2Seed1, Mesh2Seed2;

                    if( It2mesh1.first != TriLookup1.end() && It2mesh2.first != TriLookup2.end() ) {
                        // check which of seed1 and seed2 must be included (it can be 0, 1 or both)
                        Mesh1Seed1 = It2mesh1.first->second;
                        Mesh1Seed2 = (--It2mesh1.second)->second;
                        Mesh2Seed1 = It2mesh2.first->second;
                        Mesh2Seed2 = (--It2mesh2.second)->second;
                        if( Mesh1Seed1 == Mesh1Seed2 ) {
                            Mesh1Seed2 = -1;
                        }
                        if( Mesh2Seed1 == Mesh2Seed2 ) {
                            Mesh2Seed2 = -1;
                        }

                        Vector3 vMesh1, nMesh1, vMesh2, nMesh2;
                        for( Integer i = 0 ; i < 3 ; i++ )
                        {
                            const Vector3& Position = NewMesh1.GetVertices()[ NewMesh1.GetIndices()[ Mesh1Seed1 * 3 + i ] ].Position;
                            if( Position.SquaredDistance( FirstSeg.PointA ) > 1e-6 && Position.SquaredDistance( FirstSeg.PointB ) > 1e-6 ) {
                                vMesh1 = Position;
                                nMesh1 = NewMesh1.GetVertices()[ NewMesh1.GetIndices()[ Mesh1Seed1 * 3 + i ] ].Normal;
                                break;
                            }
                        }

                        for( Integer i = 0 ; i < 3 ; i++ )
                        {
                            const Vector3& Position = NewMesh2.GetVertices()[ NewMesh2.GetIndices()[ Mesh2Seed1 * 3 + i ] ].Position;
                            if( Position.SquaredDistance( FirstSeg.PointA ) > 1e-6 && Position.SquaredDistance( FirstSeg.PointB ) > 1e-6 ) {
                                vMesh2 = Position;
                                nMesh2 = NewMesh2.GetVertices()[ NewMesh2.GetIndices()[ Mesh2Seed1 * 3 + i ] ].Normal;
                                break;
                            }
                        }

                        Boole M2S1InsideM1 = ( nMesh1.DotProduct( vMesh2 - FirstSeg.PointA ) < 0 );
                        Boole M1S1InsideM2 = ( nMesh2.DotProduct( vMesh1 - FirstSeg.PointA ) < 0 );

                        _RemoveFromTriLookup( Mesh1Seed1, TriLookup1 );
                        _RemoveFromTriLookup( Mesh2Seed1, TriLookup2 );
                        _RemoveFromTriLookup( Mesh1Seed2, TriLookup1 );
                        _RemoveFromTriLookup( Mesh2Seed2, TriLookup2 );

                        // Recursively add all neighbours of these triangles
                        // Stop when a contour is touched
                        switch( this->BoolOp )
                        {
                            case BO_Union:
                            {
                                if( M1S1InsideM2 ) {
                                    _RecursiveAddNeighbour(Buffer,NewMesh1,Mesh1Seed2,TriLookup1,Limits,false);
                                }else{
                                    _RecursiveAddNeighbour(Buffer,NewMesh1,Mesh1Seed1,TriLookup1,Limits,false);
                                }
                                if( M2S1InsideM1 ) {
                                    _RecursiveAddNeighbour(Buffer,NewMesh2,Mesh2Seed2,TriLookup2,Limits,false);
                                }else{
                                    _RecursiveAddNeighbour(Buffer,NewMesh2,Mesh2Seed1,TriLookup2,Limits,false);
                                }
                                break;
                            }
                            case BO_Intersection:
                            {
                                if( M1S1InsideM2 ) {
                                    _RecursiveAddNeighbour(Buffer,NewMesh1,Mesh1Seed1,TriLookup1,Limits,false);
                                }else{
                                    _RecursiveAddNeighbour(Buffer,NewMesh1,Mesh1Seed2,TriLookup1,Limits,false);
                                }
                                if( M2S1InsideM1 ) {
                                    _RecursiveAddNeighbour(Buffer,NewMesh2,Mesh2Seed1,TriLookup2,Limits,false);
                                }else{
                                    _RecursiveAddNeighbour(Buffer,NewMesh2,Mesh2Seed2,TriLookup2,Limits,false);
                                }
                                break;
                            }
                            case BO_Difference:
                            {
                                if( M1S1InsideM2 ) {
                                    _RecursiveAddNeighbour(Buffer,NewMesh1,Mesh1Seed2,TriLookup1,Limits,false);
                                }else{
                                    _RecursiveAddNeighbour(Buffer,NewMesh1,Mesh1Seed1,TriLookup1,Limits,false);
                                }
                                if( M2S1InsideM1 ) {
                                    _RecursiveAddNeighbour(Buffer,NewMesh2,Mesh2Seed1,TriLookup2,Limits,true);
                                }else{
                                    _RecursiveAddNeighbour(Buffer,NewMesh2,Mesh2Seed2,TriLookup2,Limits,true);
                                }
                                break;
                            }
                        }
                    }
                }
            }