コード例 #1
0
ファイル: shortcut.hpp プロジェクト: aurone/sbpl_manipulation
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
ファイル: ktech.cpp プロジェクト: KINGCODESABER/ktools
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()) );
	}
}
コード例 #3
0
 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;
         }
     }
 }
コード例 #4
0
    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);
    }
コード例 #5
0
    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>()));
        }
    }
コード例 #6
0
    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());
            }
        }
    }
コード例 #7
0
    PathContainer filter(PathContainer& paths) {
        PathContainer result;

        for (size_t i = 0; i < paths.size(); ++i) {
            if (conjugateOperator(predicate(*paths.Get(i)), predicate(*paths.GetConjugate(i)))) {
                result.AddPair(paths.Get(i), paths.GetConjugate(i));
            }
        }

        return result;
    }
コード例 #8
0
    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);
            }
        }
    }
コード例 #9
0
/*!

\brief Gets a list of files stored in the zip archive.
\param[out] container PathContainer used to store the list of file in the zip archive.
\return Returns dmz::True if the container was successfully populated. Returns
dmz::False if there is no open zip archive open.

*/
dmz::Boolean
dmz::ReaderZip::get_file_list (PathContainer &container) const {

   Boolean result (False);

   if (_state.zf) {

      result = True;

      int value = unzGoToFirstFile (_state.zf);

      while (result && (UNZ_OK == value)) {

         unz_file_info info;

         const int Found = unzGetCurrentFileInfo (_state.zf, &info, 0, 0, 0, 0, 0, 0);

         if (Found == UNZ_OK && (info.size_filename > 0)) {

            char *buffer = new char[info.size_filename + 1];

            if (buffer) {

               buffer[0] = '\0';

               if (UNZ_OK == unzGetCurrentFileInfo (
                     _state.zf,
                     0, // info struct
                     buffer, info.size_filename,
                     0, 0, // extra field
                     0, 0)) { // comment field

                  buffer[info.size_filename] = '\0';

                  container.add_path (buffer);
               }

               delete []buffer; buffer = 0;
            }
         }
         else { result = _state.zip_error (Found); }

         value = unzGoToNextFile (_state.zf);
      }
   }

   return result;
}
コード例 #10
0
ファイル: ktech.cpp プロジェクト: KINGCODESABER/ktools
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);
}
コード例 #11
0
ファイル: dmzApplicationiPhone.cpp プロジェクト: rdarken/dmz
/*!

 \brief Process the command line.
 \details Loads all XML configuration files specified by the command line.
 \param[in] CL CommandLine object to process.
 \return Returns dmz::True if command line was successfully processed. Returns
 dmz::False if there was an error parsing the XML configuration files.

 */
dmz::Boolean
dmz::ApplicationiPhone::load_config (const PathContainer &Files) {

    String file;
    _state.error = False;

    while (Files.get_next (file) && !_state.error) {

        if (!xml_to_config (file, _state.global, &(_state.log))) {

            _state.errorMsg.flush () << "Unable to load config: " << file;

            _state.log.error << _state.errorMsg << endl;

            _state.error = True;
        }
    }

    if (!_state.error) {
        _state.cache.configure (_state.global);
    }

    return !_state.error;
}
コード例 #12
0
ファイル: MessageExporter.cpp プロジェクト: mmanley/Antares
// Export
status_t
MessageExporter::Export(const Icon* icon, BPositionIO* stream)
{
	status_t ret = B_OK;
	BMessage archive;

	PathContainer* paths = icon->Paths();
	StyleContainer* styles = icon->Styles();

	// paths
	if (ret == B_OK) {
		BMessage allPaths;
		int32 count = paths->CountPaths();
		for (int32 i = 0; i < count; i++) {
			VectorPath* path = paths->PathAtFast(i);
			BMessage pathArchive;
			ret = _Export(path, &pathArchive);
			if (ret < B_OK)
				break;
			ret = allPaths.AddMessage("path", &pathArchive);
			if (ret < B_OK)
				break;
		}
	
		if (ret == B_OK)
			ret = archive.AddMessage("paths", &allPaths);
	}

	// styles
	if (ret == B_OK) {
		BMessage allStyles;
		int32 count = styles->CountStyles();
		for (int32 i = 0; i < count; i++) {
			Style* style = styles->StyleAtFast(i);
			BMessage styleArchive;
			ret = _Export(style, &styleArchive);
			if (ret < B_OK)
				break;
			ret = allStyles.AddMessage("style", &styleArchive);
			if (ret < B_OK)
				break;
		}
	
		if (ret == B_OK)
			ret = archive.AddMessage("styles", &allStyles);
	}

	// shapes
	if (ret == B_OK) {
		BMessage allShapes;
		ShapeContainer* shapes = icon->Shapes();
		int32 count = shapes->CountShapes();
		for (int32 i = 0; i < count; i++) {
			Shape* shape = shapes->ShapeAtFast(i);
			BMessage shapeArchive;
			ret = _Export(shape, paths, styles, &shapeArchive);
			if (ret < B_OK)
				break;
			ret = allShapes.AddMessage("shape", &shapeArchive);
			if (ret < B_OK)
				break;
		}
	
		if (ret == B_OK)
			ret = archive.AddMessage("shapes", &allShapes);
	}

	// prepend the magic number to the file which
	// later tells us that this file is one of us
	if (ret == B_OK) {
		ssize_t size = sizeof(uint32);
		uint32 magic = B_HOST_TO_BENDIAN_INT32(kNativeIconMagicNumber);
		ssize_t written = stream->Write(&magic, size);
		if (written != size) {
			if (written < 0)
				ret = (status_t)written;
			else
				ret = B_IO_ERROR;
		}
	}

	if (ret == B_OK)
		ret = archive.Flatten(stream);

	return ret;
}
コード例 #13
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;
                            }
                        }
                    }
                }
            }