47 def __init__(self, ppm_file):
49 self.
ppm_.loadFile(ppm_file)
51 space.addDimension(0.0, self.
ppm_.getWidth())
52 space.addDimension(0.0, self.
ppm_.getHeight())
58 self.
ss_.setStateValidityChecker(partial(Plane2DEnvironment.isStateValid, self))
60 self.
ss_.getSpaceInformation().setStateValidityCheckingResolution(
61 1.0 / space.getMaximumExtent()
65 def plan(self, start_row, start_col, goal_row, goal_col):
68 start = self.
ss_.getStateSpace().allocState()
71 goal = self.
ss_.getStateSpace().allocState()
74 self.
ss_.setStartAndGoalStates(start, goal)
77 if self.
ss_.getPlanner():
78 self.
ss_.getPlanner().clear()
80 ns = self.
ss_.getProblemDefinition().getSolutionCount()
81 print(
"Found %d solutions" % ns)
82 if self.
ss_.haveSolutionPath():
83 self.
ss_.simplifySolution()
84 p = self.
ss_.getSolutionPath()
91 def recordSolution(self):
92 if not self.
ss_ or not self.
ss_.haveSolutionPath():
94 p = self.
ss_.getSolutionPath()
96 for i
in range(p.getStateCount()):
97 w = min(self.
maxWidth_, int(p.getState(i)[0]))
98 h = min(self.
maxHeight_, int(p.getState(i)[1]))
99 c = self.
ppm_.getPixel(h, w)
104 def save(self, filename):
107 self.
ppm_.saveFile(filename)
109 def isStateValid(self, state):
113 c = self.
ppm_.getPixel(h, w)
114 return c.red > 127
and c.green > 127
and c.blue > 127
129 if env.plan(0, 0, 777, 1265):