Skip to content

Commit 5ba6492

Browse files
committed
fix bug with **kwd; fix bug with lstring access of type l[i:]; add module class object in simulation; module can be created directly using moduleclass; set option early return default to false;fix bug with filename argument using lpy application
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/vplants/vplants/trunk/lpy@16886 ab253cce-29fb-0310-bb2f-979600cdbdeb
1 parent f4ed99f commit 5ba6492

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1360
-458
lines changed

share/extension/curve2Ddrawing.lpy

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
from openalea.plantgl.all import *
2+
3+
NbSteps = 20
4+
dt = 1./NbSteps
5+
print dt
6+
totlength = []
7+
8+
def Start():
9+
global totlength
10+
totlength = [(0,length(0))]
11+
12+
def plotCurve(data, xextend = None, yextend = None, pos = (0.1,-0.8), dim = (0.8,0.8), xtick = None, ytick = None ):
13+
from math import ceil, floor
14+
if len(data) > 1:
15+
print data
16+
if xextend:
17+
minx, maxx = xextend
18+
else :
19+
minx = floor(min([x for x,y in data]))
20+
maxx = ceil(max([x for x,y in data]))
21+
if yextend:
22+
miny, maxy = yextend
23+
else :
24+
miny = floor(min([y for x,y in data]))
25+
maxy = ceil(max([y for x,y in data]))
26+
xext = maxx - minx
27+
yext = maxy - miny
28+
x2Dlength, y2Dlength = dim
29+
projx = lambda x: (x2Dlength*(x-minx)/xext)
30+
projy = lambda y: (y2Dlength*(y-miny)/yext)
31+
if xtick is None:
32+
xtick = yext*0.1
33+
if ytick is None:
34+
ytick = xext*0.1
35+
36+
data = [(projx(x),projy(y)) for x,y in data]
37+
ticklength = 0.02
38+
39+
nproduce [ @2D ,(3) @M(pos[0],pos[1]) @g(Polyline2D(data,width=2))
40+
if miny <= 0 <= maxy:
41+
nproduce ,(5) @g(Polyline2D([(projx(minx),projy(0)),(projx(maxx),projy(0))]))
42+
cxtick = minx + xtick
43+
while cxtick < maxx:
44+
nproduce ,(5) @g(Polyline2D([(projx(cxtick),projy(-ticklength)),(projx(cxtick),projy(ticklength))]))
45+
cxtick += xtick
46+
if minx <= 0 <= maxx:
47+
nproduce ,(2) @g(Polyline2D([(projx(0),projy(miny)),(projx(0),projy(maxy))]))
48+
cytick = miny + ytick
49+
while cytick < maxy:
50+
nproduce ,(2) @g(Polyline2D([(projx(-ticklength),projy(cytick)),(projx(ticklength),projy(cytick))]))
51+
cytick += ytick
52+
nproduce ]
53+
54+
#import matplotlib.pyplot as plt
55+
import pylab as plt
56+
57+
def StartEach():
58+
plt.close()
59+
60+
def plotCurve2(data):
61+
if len(data) > 1:
62+
plt.plot([x for x in data], [y for y in data], '-', linewidth=2)
63+
plt.show()
64+
plt.draw()
65+
66+
Axiom: I(0,length(0))
67+
68+
derivation length: NbSteps
69+
production:
70+
71+
I(t,l) :
72+
nt = t+dt
73+
if nt >= 1.0: nt = 1.0
74+
l = length(nt)
75+
totlength.append((nt,l))
76+
produce I(nt,l)
77+
78+
79+
80+
interpretation:
81+
82+
I(t,l) :
83+
plotCurve2(totlength)
84+
plotCurve(totlength)
85+
nproduce F(l)
86+
87+
88+
endlsystem
89+
###### INITIALISATION ######
90+
91+
__lpy_code_version__ = 1.1
92+
93+
def __initialiseContext__(context):
94+
import openalea.plantgl.all as pgl
95+
length = pgl.NurbsCurve2D(
96+
ctrlPointList = pgl.Point3Array([(0, 0, 1),(0.175114, 0.0522138, 1),(0.369245, 0.047519, 1),(0.369245, 0.619904, 1),(0.558015, 0.67878, 1),(1, 0.69864, 1)]) ,
97+
)
98+
length.name = "length"
99+
panel_0 = ({'active': True, 'visible': True, 'name': 'Panel 1'},[('Function',length)])
100+
parameterset = [panel_0,]
101+
context["__functions__"] = [('length',length),]
102+
context["__curves__"] = []
103+
context["__parameterset__"] = parameterset
104+
context["length"] = pgl.QuantisedFunction(length)

src/cpp/abstractlstring.h

+30-12
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,13 @@ class AbstractLString {
218218
{ return __conststring()[getValidIndex(i)]; }
219219

220220
template<class StringType>
221-
inline StringType getRange(int i, int j) const
221+
inline StringType getRange(size_t ri, size_t rj) const
222222
{
223-
size_t ri, rj; getValidIndices(i,j,ri,rj) ;
224-
return StringType(const_begin()+ri,const_begin()+rj);
223+
const_iterator beg, end;
224+
getValidIterators(ri, rj, beg, end);
225+
//size_t ri, rj; getValidIndices(i,j,ri,rj) ;
226+
// printf("%i %i\n",ri,rj);
227+
return StringType(beg,end);
225228
}
226229

227230
inline void setAt(size_t i, const Module& m)
@@ -402,15 +405,20 @@ class AbstractLString {
402405
return (size_t)i;
403406
}
404407

405-
inline void getValidIndices(int i, int j, size_t& resi, size_t& resj) const {
406-
size_t s = size();
407-
if( i < 0 ) i += s;
408-
if( j < 0 ) j += s;
409-
if( j > s ) j = s;
410-
if (i < 0 || i >= s || j < i) throw PythonExc_IndexError("index out of range");
411-
resi =(size_t)i;
412-
resj =(size_t)j;
413-
}
408+
inline void getValidIndices(int i, int j, size_t& resi, size_t& resj) const {
409+
size_t s = size();
410+
printf("%i, %i\n",i,j);
411+
if( i < 0 ) i += s;
412+
if( j < 0 ) j += s;
413+
if( j > s ) j = s;
414+
if (i < 0 || i >= s || j < i) throw PythonExc_IndexError("index out of range");
415+
resi =(size_t)i;
416+
resj =(size_t)j;
417+
}
418+
419+
inline void getValidIndices(size_t& resi, size_t& resj) const {
420+
if (resj == std::string::npos) resj = size();
421+
}
414422

415423
inline void getValidIterators(int i, int j, const_iterator& resi, const_iterator& resj) const {
416424
size_t s = size();
@@ -421,6 +429,16 @@ class AbstractLString {
421429
resi =const_begin()+i;
422430
resj =const_begin()+j;
423431
}
432+
433+
inline void getValidIterators(size_t i, size_t j, const_iterator& resi, const_iterator& resj) const {
434+
resi =const_begin()+i;
435+
if (j == LONG_MAX) {
436+
resj = const_end();
437+
}
438+
else {
439+
resj =const_begin()+j;
440+
}
441+
}
424442
};
425443

426444
/*---------------------------------------------------------------------------*/

src/cpp/lpy_parser.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Lsystem::set( const std::string& _rules , std::string * pycode,
328328
if (initpos != std::string::npos) endpycode = rules.begin()+initpos;
329329

330330
while(_it!=endpycode){
331-
printf("******'%c' %i\n",*_it,std::distance(begcode,_it));
331+
// printf("******'%c' %i\n",*_it,std::distance(begcode,_it));
332332
switch(mode){
333333
case -1:
334334
{
@@ -398,7 +398,6 @@ Lsystem::set( const std::string& _rules , std::string * pycode,
398398
if(has_keyword_pattern(_it,begcode,endpycode,"module")){
399399
code+=std::string(beg,_it2);
400400
LpyParsing::ModLineDeclaration modules = LpyParsing::parse_moddeclaration_line(_it,endpycode);
401-
code+="# "+std::string(_it2,_it);
402401
int scale = ModuleClass::DEFAULT_SCALE;
403402
ModuleClassList inheritance;
404403
pgl_hash_map_string<boost::python::object> properties;
@@ -475,6 +474,12 @@ Lsystem::set( const std::string& _rules , std::string * pycode,
475474
if(scale != ModuleClass::DEFAULT_SCALE)mod->setScale(scale);
476475
if(!inheritance.empty())mod->setBases(inheritance);
477476
}
477+
for(LpyParsing::ModDeclarationList::const_iterator itmod = modules.first.begin();
478+
itmod != modules.first.end(); ++itmod){
479+
if (itmod != modules.first.begin()) code += " ; ";
480+
code += itmod->name+" = ModuleClass.get('"+itmod->name+"')";
481+
}
482+
code+="# "+std::string(_it2,_it);
478483
beg = _it;
479484
toendlineA(_it,endpycode);
480485
}

src/cpp/lstringmatcher.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool LstringMatcher::inLeftContext(const PatternString& pattern, boost::python::
9494
bool LstringMatcher::pInRightContext(size_t patternid, boost::python::dict& args)
9595
{
9696
PatternString pattern = PatternStringManager::get().get_pattern(patternid);
97-
return inLeftContext(pattern,args);
97+
return inRightContext(pattern,args);
9898
}
9999

100100
bool LstringMatcher::inRightContext(const PatternString& pattern, boost::python::dict& args)

src/cpp/lstringmatcher.h

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class LstringMatcher : public TOOLS(RefCountObject) {
7373

7474
typedef RCPtr<LstringMatcher> LstringMatcherPtr;
7575

76+
class LsysContext;
77+
7678
struct LstringMatcherMaintainer {
7779
LsysContext * context;
7880

src/cpp/lsyscontext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void LsysContext::init_options()
367367
option = options.add("Early return when no matching","Set whether the L-systems end prematurely if no matching has occured in the last iteration.","Processing");
368368
option->addValue("Disabled",this,&LsysContext::setReturnIfNoMatching,false,"Disable early return.");
369369
option->addValue("Enabled",this,&LsysContext::setReturnIfNoMatching,true,"Enable early return.");
370-
option->setDefault(1);
370+
option->setDefault(0);
371371
#if (PGL_VERSION >= 0x020B00)
372372
/** warn if turtle has invalid value option */
373373
option = options.add("Warning with Turtle inconsistency","Set whether a warning/error is raised when an invalid value is found during turtle processing.","Processing");

src/cpp/lsyscontext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class LPY_API LsysContext {
157157
/** static functions to access context */
158158
static inline LsysContext * currentContext() { return current(); }
159159
static LsysContext * current();
160-
static inline LsysContext * globalContext();
160+
static LsysContext * globalContext();
161161

162162
// { return global(); }
163163
// static LsysContext * global();

src/cpp/lsysrule.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,17 @@ LsysRule::match(const AxialTree& src,
535535
ArgList args_ncd;
536536
if(!MatchingEngine::right_match(dest.const_begin(),dest.const_begin(),dest.const_end(),
537537
__newrightcontext.const_begin(),__newrightcontext.const_end(),
538-
<<<<<<< .mine endposNewRightLastMatch,endposNewRight,args_ncd))return false;
539-
======= last_match,endpos2,args_ncd))
540-
return false;
541-
>>>>>>> .theirs ArgsCollector::append_args(args,args_ncd);
538+
endposNewRightLastMatch,endposNewRight,args_ncd)) return false;
539+
// last_match,endpos2,args_ncd)) return false;
540+
ArgsCollector::append_args(args,args_ncd);
542541
}
543542

544543
// right context
545544
AxialTree::const_iterator endposRight = endpos1;
546545
AxialTree::const_iterator endposRightLastMatch = last_match;
547546
if(!__rightcontext.empty()){
548547
ArgList args_cd;
549-
if(!MatchingEngine::right_match(endpos1,src.const_begin(),src.const_end(),
548+
if(!MatchingEngine::right_match(endposRight,src.const_begin(),src.const_end(),
550549
__rightcontext.const_begin(),__rightcontext.const_end(),
551550
endposRightLastMatch,endposRight,args_cd))return false;
552551
ArgsCollector::append_args(args,args_cd);

0 commit comments

Comments
 (0)