Skip to content

Commit

Permalink
Fixing bugs in road generating algorithms and street graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
pazdera committed Apr 14, 2011
1 parent 0e49c65 commit 8c01a97
Show file tree
Hide file tree
Showing 28 changed files with 571 additions and 290 deletions.
40 changes: 20 additions & 20 deletions include/libcity.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
#ifndef __LIBCITY_H_
#define __LIBCITY_H_

namespace libcity
{
#include "geometry/point.h"
#include "geometry/line.h"
#include "geometry/vector.h"
#include "geometry/polygon.h"

#include "streetgraph/road.h"
#include "streetgraph/intersection.h"
#include "streetgraph/streetgraph.h"
#include "streetgraph/rasterroadpattern.h"
#include "streetgraph/organicroadpattern.h"
#include "streetgraph/minimalcyclebasis.h"
#include "../src/geometry/point.h"
#include "../src/geometry/line.h"
#include "../src/geometry/vector.h"
#include "../src/geometry/polygon.h"

#include "lsystem/lsystem.h"
#include "lsystem/graphiclsystem.h"
#include "lsystem/roadlsystem.h"
#include "../src/streetgraph/road.h"
#include "../src/streetgraph/path.h"
#include "../src/streetgraph/intersection.h"
#include "../src/streetgraph/streetgraph.h"
#include "../src/streetgraph/zone.h"
#include "../src/streetgraph/rasterroadpattern.h"
#include "../src/streetgraph/organicroadpattern.h"
#include "../src/streetgraph/minimalcyclebasis.h"

#include "random.h"
#include "city.h"
#include "debug.h"
}
#include "../src/lsystem/lsystem.h"
#include "../src/lsystem/graphiclsystem.h"
#include "../src/lsystem/roadlsystem.h"

#endif
#include "../src/random.h"
#include "../src/city.h"
#include "../src/debug.h"

#endif
21 changes: 12 additions & 9 deletions plan.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ Plan:
- DONE implement iterating through street graph
- PARTIALY DONE refactor streetgraph modifying algorithm
- DONE figure how to iterate through roads in streetgraph
- implement streetgraph.divideToZones()
- create LSystem class for each road pattern (checkquers, organic, radial)
- bug fixing
- DONE implement streetgraph.divideToZones()
- DONE create LSystem class for each road pattern (checkquers, organic, radial)
- DONE bug fixing
- DONE remove trimOverlapingPart from line
- DONE create github project page
- Make Intersections available outside the StreetGraph
- Write basic skeleton of precomputeIntersections
- How to work with Rays?
- Create texture for 3 and 4 way intersections
- Eliminate 5 and more way intersections in roadGenerators
- Make drawing roads more configurable
-
- design error handling and exceptions
- think about thesis chapters

- FIX area and centroid computation in Polygon!!! will not work in 3D

- NAPAD: GraphicInformation je jen base. V odvozenych tridach si muzeme pro kazdy symbol udelat decka. Pro ruzne typy symbolu
a pak s nimi tak pracovat. To umozni udelat streetgraph primo v lsystemu.
- NAPAD: Road lze zkonstruhovat jen s určenou low level reprezentací high level příjde potom
- NAPAD: Generator nahodnych čísel jako singleton
- NAPAD: podobnost dvou úseček zjistit vzdálenost počátku a konce jedné úsečky a druhé. Pokud jsou tyto vzdálenosti pod SNAP_DISTANCE, zdar.
3 changes: 3 additions & 0 deletions src/city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "streetgraph/streetgraph.h"
#include "streetgraph/zone.h"
#include "geometry/polygon.h"

City::City()
{
Expand All @@ -26,13 +27,15 @@ City::~City()

void City::initialize()
{
area = new Polygon;
map = new StreetGraph;
zones = new std::list<Zone*>;
}
void City::freeMemory()
{
delete map;
delete zones;
delete area;
}

void City::generate()
Expand Down
13 changes: 7 additions & 6 deletions src/city.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@

class StreetGraph;
class Zone;
class Polygon;

class City
{
public:
City();
virtual ~City();

virtual void generate();
virtual void draw();

private: /* Copying not allowed */
City(City const& source);
City& operator=(City const& source);
Expand All @@ -33,19 +37,16 @@ class City
virtual void createSecondaryRoadNetwork() = 0;
virtual void createBlocks() = 0;
virtual void createBuildings() = 0;
public:
virtual void generate();

protected:
virtual void drawRoadNetwork() = 0;
virtual void drawBuildings() = 0;
public:
virtual void draw();

private:
StreetGraph* map;
std::list<Zone*> *zones;

Polygon* area;

private:
void initialize();
void freeMemory();
};
Expand Down
8 changes: 4 additions & 4 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
#define __DEBUG_H_

#include <iostream>
#include <assert.h>

/* Debugging is ON */
#define DEBUG


#ifdef DEBUG
#define debug(x) std::cerr << "DEBUG: " << x << std::endl
#define debug(x) std::cerr << "DEBUG: " << x << std::endl
#else
#define debug(x)
#define debug(x)
#define NDEBUG /* Turn off asserts */
#endif

#include <assert.h>

#endif
10 changes: 10 additions & 0 deletions src/geometry/point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

#include "point.h"
#include "vector.h"
#include "units.h"

#include <sstream>
Expand Down Expand Up @@ -80,6 +81,15 @@ bool Point::operator>(Point const& second)
return false;
}

Point& Point::operator+=(Vector const& difference)
{
xPosition += difference.x();
yPosition += difference.y();
zPosition += difference.z();

return *this;
}

std::string Point::toString()
{
std::stringstream convertor;
Expand Down
4 changes: 4 additions & 0 deletions src/geometry/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <string>

class Vector;

class Point
{
public:
Expand Down Expand Up @@ -44,6 +46,8 @@ class Point
bool operator==(Point const& second);
bool operator<(Point const& second);
bool operator>(Point const& second);

Point& operator+=(Vector const& difference);
};

inline double Point::x() const
Expand Down
12 changes: 8 additions & 4 deletions src/geometry/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,18 @@ Point Polygon::centroid() const
currentVertex = vertices->at(currentVertexPosition);
nextVertex = vertices->at((currentVertexPosition + 1) % count);

areaStep = currentVertex->x() * nextVertex->y() - currentVertex->y() * nextVertex->x();
areaStep = currentVertex->x() * nextVertex->y() - nextVertex->x() * currentVertex->y();
area += areaStep;

x += (currentVertex->x() * nextVertex->x()) / areaStep;
y += (currentVertex->y() * nextVertex->y()) / areaStep;
x += (currentVertex->x() + nextVertex->x()) * areaStep;
y += (currentVertex->y() + nextVertex->y()) * areaStep;
}

return Point(x/(3*area), (y/3*area));
Point centroid(x/(6*(area/2)), y/(6*(area/2)));
debug(area/2);
debug(signedArea());
debug("Polygon::centroid() is " << centroid.toString());
return centroid;
}

bool Polygon::encloses2D(Point const& point) const
Expand Down
2 changes: 1 addition & 1 deletion src/lsystem/lsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ char LSystem::ProductionRule::predecessor() const
std::string LSystem::ProductionRule::successor() const
{
Random generator;
return rightSide[generator.integerValue(0, rightSide.size() - 1)];
return rightSide[generator.generateInteger(0, rightSide.size() - 1)];
}

/* ********************* */
Expand Down
Loading

0 comments on commit 8c01a97

Please sign in to comment.