Skip to content

Commit

Permalink
Now geomodelr deletes geojson by default so more memory is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Serrano committed Jun 15, 2017
1 parent 2f9ec08 commit c2c80a1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions geomodelr/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ParametersException(Exception):
pass

def prep_model(geojson):
model = GeologicalModel(json.loads(geojson.read()))
model = GeologicalModel(json.loads(geojson.read()), delete=False)
return model

def query_coordinates(geojson, verbose=False):
Expand Down Expand Up @@ -134,7 +134,7 @@ def query_func(p):

def get_information(geojson, verbose):
# Show map, cross sections, polygons, etc.
model = GeologicalModel(json.loads(geojson.read()))
model = GeologicalModel(json.loads(geojson.read()), delete=False)
model.print_information(verbose)

def main(args=None):
Expand Down
1 change: 1 addition & 0 deletions geomodelr/cpp/geomodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ BOOST_PYTHON_MODULE(cpp)
.def("signed_distance_bounded", &ModelPython::signed_distance_bounded, python::args("unit", "point"), doc_signed_distance_bounded)
.def("height", &ModelPython::height, python::args("point"), doc_height)
.def("info", &ModelPython::info)
.add_property("bbox", &ModelPython::pybbox)
.add_property("matches", &ModelPython::get_matches, &ModelPython::set_matches);
}

Expand Down
11 changes: 11 additions & 0 deletions geomodelr/cpp/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,17 @@ pylist ModelPython::get_matches( ) const {
return ret;
}

pylist ModelPython::pybbox( ) const {
pylist p;
p.append( g0( g0( this->bbox ) ) );
p.append( g1( g0( this->bbox ) ) );
p.append( g2( g0( this->bbox ) ) );
p.append( g0( g1( this->bbox ) ) );
p.append( g1( g1( this->bbox ) ) );
p.append( g2( g1( this->bbox ) ) );
return p;
}

double ModelPython::signed_distance( const wstring& unit, const pyobject& pt ) const {
return ((Model *)this)->signed_distance(unit, point3(python::extract<double>(pt[0]), python::extract<double>(pt[1]), python::extract<double>(pt[2])));
}
Expand Down
6 changes: 5 additions & 1 deletion geomodelr/cpp/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class TopographyPython : public Topography {
class Model {
protected:
std::pair<double, double> cuts_range;
std::tuple<std::tuple<double, double, double>, std::tuple<double, double, double>> bbox;
std::tuple<std::tuple<double, double, double>,
std::tuple<double, double, double>> bbox;

point2 base_point;
point2 direction;
vector<Section *> sections;
Expand Down Expand Up @@ -87,6 +89,7 @@ class Model {
return Possible(cls.first, -1, cls.second, cls.second+s_dist);
}
};

// Given a match in section b, find a match in section b.
auto b_possible = [&](const std::pair<int, double>& cls) {
if ( cls.first == -1 ) {
Expand Down Expand Up @@ -270,6 +273,7 @@ class ModelPython : public Model {
pylist get_matches() const;
// Methods to query matches.
pylist possible_closest(const pyobject& pt) const;
pylist pybbox() const;
pytuple model_point(const pyobject& pt) const;
pytuple inverse_point(const pyobject& pt) const;
pytuple closest(const pyobject& pt) const;
Expand Down
7 changes: 6 additions & 1 deletion geomodelr/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class GeologicalModel(cpp.Model):
with a transformation. Go to Geomodelr.com, create a new model and use it with this
tool.
"""
def __init__( self, geolojson ):
def __init__( self, geolojson, delete=True ):
"""
Initializes the geological model from a Geological JSON
file created in www.geomodelr.com.
Expand Down Expand Up @@ -127,7 +127,12 @@ def __init__( self, geolojson ):
bbox = self.geojson['bbox']
super(GeologicalModel, self).__init__(bbox, list(base_point), list(direction), geomap, topography, sections)
self.make_matches()

# Save space.
if delete:
del self.geojson


def make_matches(self):
""" Prepares the model to query by matching polygons and lines.
It finds which polygons, when projected to the next cross section,
Expand Down
2 changes: 1 addition & 1 deletion geomodelr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def fix_solid( vertices, triangles ):

def calculate_isosurface(model, unit, grid_divisions):

bbox = list(model.geojson['bbox']) # Copy so original is not modified.
bbox = list(model.bbox) # Copy so original is not modified.

dx = (bbox[3]-bbox[0])/grid_divisions
dy = (bbox[4]-bbox[1])/grid_divisions
Expand Down

0 comments on commit c2c80a1

Please sign in to comment.