Changeset 173

Show
Ignore:
Timestamp:
03/04/10 09:33:28 (5 months ago)
Author:
hobu
Message:

add CountVisitor? to the CAPI to provide a cumulation of the number of hits that land within a query

Location:
spatialindex/trunk
Files:
6 modified
2 copied

Legend:

Unmodified
Added
Removed
  • spatialindex/trunk/include/capi/CountVisitor.h

    r172 r173  
    11/****************************************************************************** 
    2  * $Id: idvisitor.hpp 1361 2009-08-02 17:53:31Z hobu $ 
    3  * 
    4  * Project:  libsidx - A C API wrapper around libspatialindex 
    5  * Purpose:  C++ object declarations to implement the wrapper. 
    6  * Author:   Howard Butler, hobu.inc@gmail.com 
    7  * 
    8  ****************************************************************************** 
    9  * Copyright (c) 2009, Howard Butler 
    10  * 
    11  * All rights reserved. 
    12  *  
    13  * This library is free software; you can redistribute it and/or modify it under 
    14  * the terms of the GNU Lesser General Public License as published by the Free 
    15  * Software Foundation; either version 2.1 of the License, or (at your option) 
    16  * any later version. 
     2* $Id$ 
     3* 
     4* Project:  libsidx - A C API wrapper around libspatialindex 
     5* Purpose:  C++ objects to implement the count visitor. 
     6* Author:   Leonard NorrgÃ¥rd, leonard.norrgard@refactor.fi 
     7* 
     8****************************************************************************** 
     9* Copyright (c) 2010, Leonard NorrgÃ¥rd 
     10* 
     11* All rights reserved. 
     12*  
     13* This library is free software; you can redistribute it and/or modify it under 
     14* the terms of the GNU Lesser General Public License as published by the Free 
     15* Software Foundation; either version 2.1 of the License, or (at your option) 
     16* any later version. 
    1717 
    18  * This library is distributed in the hope that it will be useful, but WITHOUT 
    19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    20  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
    21  * details. 
    22  *  
    23  * You should have received a copy of the GNU Lesser General Public License  
    24  * along with this library; if not, write to the Free Software Foundation, Inc., 
    25  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
    26  ****************************************************************************/ 
     18* This library is distributed in the hope that it will be useful, but WITHOUT 
     19* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     20* FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
     21* details. 
     22*  
     23* You should have received a copy of the GNU Lesser General Public License  
     24* along with this library; if not, write to the Free Software Foundation, Inc., 
     25* 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
     26****************************************************************************/ 
    2727 
    2828#pragma once 
    2929 
    30 class IdVisitor : public SpatialIndex::IVisitor 
     30class CountVisitor : public SpatialIndex::IVisitor 
    3131{ 
    3232private: 
    33     std::vector<uint64_t> m_vector; 
    34     uint64_t nResults; 
     33   uint64_t nResults; 
    3534 
    3635public: 
    3736 
    38     IdVisitor(); 
    39     ~IdVisitor(); 
     37   CountVisitor(); 
     38   ~CountVisitor(); 
    4039 
    41     uint64_t GetResultCount() const { return nResults; } 
    42     std::vector<uint64_t>& GetResults()  { return m_vector; } 
    43      
    44     void visitNode(const SpatialIndex::INode& n); 
    45     void visitData(const SpatialIndex::IData& d); 
    46     void visitData(std::vector<const SpatialIndex::IData*>& v); 
     40   uint64_t GetResultCount() const { return nResults; } 
     41 
     42   void visitNode(const SpatialIndex::INode& n); 
     43   void visitData(const SpatialIndex::IData& d); 
     44   void visitData(std::vector<const SpatialIndex::IData*>& v); 
    4745}; 
  • spatialindex/trunk/include/capi/Makefile.am

    r144 r173  
    33dist_spatialindex_HEADERS =     \ 
    44                                                                BoundsQuery.h \ 
     5                                                                CountVisitor.h \ 
    56                                                                DataStream.h \ 
    67                                                                Error.h \ 
    7                                                                 LeafQuery.h \ 
    88                                                                IdVisitor.h \ 
    99                                                                Index.h \ 
     10                                                                LeafQuery.h \ 
    1011                                                                ObjVisitor.h \ 
    1112                                                                sidx_api.h \ 
  • spatialindex/trunk/include/capi/sidx_api.h

    r172 r173  
    7575                                                                                uint64_t* nResults); 
    7676                                                                                 
     77SIDX_DLL RTError Index_Intersects_count(        IndexH index,  
     78                                                                                double* pdMin,  
     79                                                                                double* pdMax,  
     80                                                                                uint32_t nDimension,  
     81                                                                                uint64_t* nResults); 
    7782SIDX_DLL RTError Index_NearestNeighbors_obj(IndexH index,  
    7883                                                                                        double* pdMin,  
  • spatialindex/trunk/include/capi/sidx_impl.h

    r144 r173  
    3838#include <capi/ObjVisitor.h> 
    3939#include <capi/IdVisitor.h> 
     40#include <capi/CountVisitor.h> 
    4041#include <capi/BoundsQuery.h> 
    4142#include <capi/LeafQuery.h> 
  • spatialindex/trunk/makefile.vc

    r153 r173  
    137137         
    138138COBJS = src\capi\BoundsQuery.obj \ 
     139        src\capi\CountVisitor.obj \ 
    139140        src\capi\DataStream.obj \ 
    140141        src\capi\Error.obj \ 
  • spatialindex/trunk/src/capi/CountVisitor.cc

    r138 r173  
     1 
    12/****************************************************************************** 
    2  * $Id: idvisitor.cc 1361 2009-08-02 17:53:31Z hobu $ 
    3  * 
    4  * Project:  libsidx - A C API wrapper around libspatialindex 
    5  * Purpose:  C++ objects to implement the id visitor. 
    6  * Author:   Howard Butler, hobu.inc@gmail.com 
    7  * 
    8  ****************************************************************************** 
    9  * Copyright (c) 2009, Howard Butler 
    10  * 
    11  * All rights reserved. 
    12  *  
    13  * This library is free software; you can redistribute it and/or modify it under 
    14  * the terms of the GNU Lesser General Public License as published by the Free 
    15  * Software Foundation; either version 2.1 of the License, or (at your option) 
    16  * any later version. 
     3* $Id$ 
     4* 
     5* Project:  libsidx - A C API wrapper around libspatialindex 
     6* Purpose:  C++ objects to implement the count visitor. 
     7* Author:   Leonard NorrgÃ¥rd, leonard.norrgard@refactor.fi 
     8* 
     9****************************************************************************** 
     10* Copyright (c) 2010, Leonard NorrgÃ¥rd 
     11* 
     12* All rights reserved. 
     13*  
     14* This library is free software; you can redistribute it and/or modify it under 
     15* the terms of the GNU Lesser General Public License as published by the Free 
     16* Software Foundation; either version 2.1 of the License, or (at your option) 
     17* any later version. 
    1718 
    18  * This library is distributed in the hope that it will be useful, but WITHOUT 
    19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
    20  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
    21  * details. 
    22  *  
    23  * You should have received a copy of the GNU Lesser General Public License  
    24  * along with this library; if not, write to the Free Software Foundation, Inc., 
    25  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
    26  ****************************************************************************/ 
     19* This library is distributed in the hope that it will be useful, but WITHOUT 
     20* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
     21* FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
     22* details. 
     23*  
     24* You should have received a copy of the GNU Lesser General Public License  
     25* along with this library; if not, write to the Free Software Foundation, Inc., 
     26* 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
     27****************************************************************************/ 
    2728 
    2829#include "sidx_impl.h" 
    2930 
    30 IdVisitor::IdVisitor(): nResults(0) 
     31CountVisitor::CountVisitor(): nResults(0) 
    3132{ 
    3233} 
    3334 
    34 IdVisitor::~IdVisitor() 
     35CountVisitor::~CountVisitor() 
    3536{ 
    3637 
    3738} 
    3839 
    39 void IdVisitor::visitNode(const SpatialIndex::INode& n) 
     40void CountVisitor::visitNode(const SpatialIndex::INode& n) 
    4041{ 
    4142 
    4243} 
    4344 
    44 void IdVisitor::visitData(const SpatialIndex::IData& d) 
     45void CountVisitor::visitData(const SpatialIndex::IData& d) 
    4546{ 
    46     nResults += 1; 
    47      
    48     m_vector.push_back(d.getIdentifier()); 
     47   nResults += 1; 
    4948} 
    5049 
    51 void IdVisitor::visitData(std::vector<const SpatialIndex::IData*>& v) 
     50void CountVisitor::visitData(std::vector<const SpatialIndex::IData*>& v) 
    5251{ 
    5352} 
  • spatialindex/trunk/src/capi/Makefile.am

    r144 r173  
    22noinst_LTLIBRARIES = libsidxc.la 
    33INCLUDES = -I../../include -I../../include/capi 
    4 libsidxc_la_SOURCES =   BoundsQuery.cc \ 
     4libsidxc_la_SOURCES =   BoundsQuery.cc \ 
     5                                                CountVisitor.cc \ 
    56                                                DataStream.cc \ 
    67                                                Error.cc \ 
    7                                                 LeafQuery.cc \ 
    88                                                IdVisitor.cc \ 
    99                                                Index.cc \ 
     10                                                LeafQuery.cc \ 
    1011                                                ObjVisitor.cc \ 
    1112                                                sidx_api.cc \ 
  • spatialindex/trunk/src/capi/sidx_api.cc

    r172 r173  
    378378} 
    379379 
     380SIDX_C_DLL RTError Index_Intersects_count(        IndexH index,  
     381                                                                                double* pdMin,  
     382                                                                                double* pdMax,  
     383                                                                                uint32_t nDimension,  
     384                                                                                uint64_t* nResults) 
     385{ 
     386        VALIDATE_POINTER1(index, "Index_Intersects_count", RT_Failure);    
     387        Index* idx = static_cast<Index*>(index); 
     388 
     389        CountVisitor* visitor = new CountVisitor; 
     390        try { 
     391        SpatialIndex::Region* r = new SpatialIndex::Region(pdMin, pdMax, nDimension); 
     392                idx->index().intersectsWithQuery(       *r,  
     393                                                                                        *visitor); 
     394 
     395                *nResults = visitor->GetResultCount(); 
     396 
     397                delete r; 
     398                delete visitor; 
     399 
     400        } catch (Tools::Exception& e) 
     401        { 
     402                Error_PushError(RT_Failure,  
     403                                                e.what().c_str(),  
     404                                                "Index_Intersects_count"); 
     405                delete visitor; 
     406                return RT_Failure; 
     407        } catch (std::exception const& e) 
     408        { 
     409                Error_PushError(RT_Failure,  
     410                                                e.what(),  
     411                                                "Index_Intersects_count"); 
     412                delete visitor; 
     413                return RT_Failure; 
     414        } catch (...) { 
     415                Error_PushError(RT_Failure,  
     416                                                "Unknown Error",  
     417                                                "Index_Intersects_count"); 
     418                delete visitor; 
     419                return RT_Failure;                 
     420        } 
     421        return RT_None; 
     422} 
     423 
    380424SIDX_C_DLL RTError Index_NearestNeighbors_id(IndexH index,  
    381425                                                                                        double* pdMin,