Commit 9c4d995b authored by Jund Thomas's avatar Jund Thomas
Browse files

import building avc extrusion ok

parent 5876d497
......@@ -28,6 +28,9 @@ template <typename PFP>
Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d,
CellMarker<FACE>& buildingMark, float height) ;
template <typename PFP>
Dart extrudeBuilding(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, unsigned int buildingType, float height);
#ifndef SPATIAL_HASHING
template <typename PFP>
bool animateCity(EnvMap* envMap) ;
......
......@@ -207,6 +207,71 @@ Dart extrudeFaceAndMark(typename PFP::MAP& map, typename PFP::TVEC3& position, D
return dRoof ;
}
template <typename PFP>
Dart extrudeBuilding(typename PFP::MAP& map, typename PFP::TVEC3& position, Dart d, unsigned int buildingType, float height)
{
Dart dRoof ;
VEC3 sky(0,0,1.0f);
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, d, sky*height) ;
switch (buildingType)
{
case 0 : //basic
{
break ;
}
case 1 : //with roof 1 slope
{
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoof, sky*height/3.0f) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
break ;
}
case 2 : //with roof 2 slopes
{
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoof, sky*height/3.0f) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
typename PFP::VEC3 mid1 = (position[dNext] + position[map.phi1(dNext)]) / 2.0f ;
typename PFP::VEC3 mid2 = (position[dPrev] + position[map.phi1(dPrev)]) / 2.0f ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
position[dRoof] = mid2 ;
position[map.phi1(dRoof)] = mid1 ;
break ;
}
case 3 : //with multiple stairs
{
unsigned int nbStairs = rand() % 5 ;
for (unsigned int i = 0; i < nbStairs; ++i)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
Dart dRoofSmall = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoof, 0.0f) ;
Dart dd = dRoofSmall ;
do
{
position[dd] = position[dd] + (c - position[dd]) / 3.0f ;
dd = map.phi1(dd) ;
} while (dd != dRoofSmall) ;
dRoof = Algo::Modelisation::extrudeFace<PFP>(map, position, dRoofSmall, sky*height/2.0f) ;
}
bool spike = rand() % 2 ;
if (spike)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
c[2] += height / 1.5f ;
dRoof = Algo::Modelisation::trianguleFace<PFP>(map, dRoof) ;
position[dRoof] = c ;
}
break ;
}
}
return dRoof;
}
#ifndef SPATIAL_HASHING
template <typename PFP>
bool animateCity(EnvMap* envMap)
......@@ -363,58 +428,58 @@ Dart generateBuilding(EnvMap& envMap, Dart d, float height, unsigned int buildin
switch (buildingType)
{
case 0 :
{
break ;
}
case 1 :
{
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
break ;
}
case 2 :
{
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
typename PFP::VEC3 mid1 = (position[dNext] + position[map.phi1(dNext)]) / 2.0f ;
typename PFP::VEC3 mid2 = (position[dPrev] + position[map.phi1(dPrev)]) / 2.0f ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
position[dRoof] = mid2 ;
position[map.phi1(dRoof)] = mid1 ;
break ;
}
case 3 :
{
unsigned int nbStairs = rand() % 5 ;
for (unsigned int i = 0; i < nbStairs; ++i)
case 0 :
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
Dart dRoofSmall = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, 0.0f) ;
Dart dd = dRoofSmall ;
do
{
position[dd] = position[dd] + (c - position[dd]) / 3.0f ;
dd = map.phi1(dd) ;
} while (dd != dRoofSmall) ;
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoofSmall, buildingMark,
height / 2.0f) ;
break ;
}
bool spike = rand() % 2 ;
if (spike)
case 1 :
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
c[2] += height / 1.5f ;
dRoof = Algo::Modelisation::trianguleFace<PFP>(map, dRoof) ;
position[dRoof] = c ;
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
break ;
}
case 2 :
{
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, height / 3) ;
Dart dNext = map.phi1(dRoof) ;
Dart dPrev = map.phi2(map.phi_1(dRoof)) ;
typename PFP::VEC3 mid1 = (position[dNext] + position[map.phi1(dNext)]) / 2.0f ;
typename PFP::VEC3 mid2 = (position[dPrev] + position[map.phi1(dPrev)]) / 2.0f ;
map.collapseEdge(dNext) ;
map.collapseEdge(dPrev) ;
position[dRoof] = mid2 ;
position[map.phi1(dRoof)] = mid1 ;
break ;
}
case 3 :
{
unsigned int nbStairs = rand() % 5 ;
for (unsigned int i = 0; i < nbStairs; ++i)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
Dart dRoofSmall = extrudeFaceAndMark<PFP>(map, position, dRoof, buildingMark, 0.0f) ;
Dart dd = dRoofSmall ;
do
{
position[dd] = position[dd] + (c - position[dd]) / 3.0f ;
dd = map.phi1(dd) ;
} while (dd != dRoofSmall) ;
dRoof = extrudeFaceAndMark<PFP>(map, position, dRoofSmall, buildingMark,
height / 2.0f) ;
}
bool spike = rand() % 2 ;
if (spike)
{
typename PFP::VEC3 c = Algo::Geometry::faceCentroid<PFP>(map, dRoof, position) ;
c[2] += height / 1.5f ;
dRoof = Algo::Modelisation::trianguleFace<PFP>(map, dRoof) ;
position[dRoof] = c ;
}
break ;
}
break ;
}
}
return dRoof ;
......
......@@ -8,6 +8,7 @@
#include "Geometry/inclusion.h"
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Modelisation/triangulation.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Import/importSvg.h"
#include "Algo/BooleanOperator/mergeVertices.h"
......@@ -37,6 +38,7 @@ EnvMap::EnvMap() :
normal = map.addAttribute<VEC3, VERTEX>("normal") ;
positionScenary = mapScenary.addAttribute<VEC3, VERTEX>("position") ;
normalScenary = mapScenary.addAttribute<VEC3, VERTEX>("normal") ;
#ifndef SPATIAL_HASHING
agentvect = map.addAttribute<PFP::AGENTVECT, FACE>("agents") ;
......@@ -100,11 +102,65 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
std::string filename2 = "./svg/mapBuild.svg" ;
Algo::Import::importSVG<PFP>(mapScenary, filename2, positionScenary, obstacleMarkS, buildingMarkS) ;
// TraversorF<PFP::MAP> tF(mapScenary);
// for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next())
// {
// CityGenerator::generateBuilding(mapScenary,d,5,1);
// }
TraversorF<PFP::MAP> tF(mapScenary);
for(Dart d = tF.begin() ; d != tF.end() ; d = tF.next())
{
//test if convex
bool convex=true;
Dart dd = mapScenary.phi1(d);
Dart dN = mapScenary.phi1(dd);
Dart dNN = mapScenary.phi1(dN);
VEC3 p1, p2, p3, v1, v2;
p1 = positionScenary[dd];
p2 = positionScenary[dN];
p3 = positionScenary[dNN];
v1 = VEC3(p2-p1);
v2 = VEC3(p3-p2);
float sign = (v1^v2)[2];
while(convex && dd!=d)
{
dd=dN;
dN = dNN;
dNN = mapScenary.phi1(dNN);
p1 = positionScenary[dd];
p2 = positionScenary[dN];
p3 = positionScenary[dNN];
v1 = VEC3(p2-p1);
v2 = VEC3(p3-p2);
float sign2 = (v1^v2)[2];
if((sign<0 && sign2>0) || (sign>0 && sign2<0))
convex=false;
}
//make extrusion/roof/..
if(convex)
{
if(Algo::Geometry::convexFaceArea<PFP>(mapScenary, d, positionScenary)<20.0f) //if big enough create building with "stairs"
CityGenerator::extrudeBuilding<PFP>(mapScenary,positionScenary, d,1+rand()%2,10.0f*(1.0f+rand()/RAND_MAX));
else //create building with simple roof
CityGenerator::extrudeBuilding<PFP>(mapScenary,positionScenary, d,3,10.0f*(1.0f+rand()/RAND_MAX));
}
else //building with no roof
{
CityGenerator::extrudeBuilding<PFP>(mapScenary,positionScenary, d,0,5.0f+5.0f*(1.0f+2.0f*rand()/RAND_MAX));
}
}
//triangulation for rendering
Algo::Modelisation::EarTriangulation<PFP> et(mapScenary);
et.triangule();
//subdivision to create footpath
// SelectorDartNoBoundary<PFP::MAP> nb(map);
// Algo::Modelisation::TwoNPlusOneSubdivision<PFP,PFP::TVEC3, VEC3>(map,position,nb);
// Algo::BooleanOperator::mergeVertices<PFP>(map, position) ;
// map.closeMap() ;
......
......@@ -413,6 +413,7 @@ void SocialAgents::cb_redraw()
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) ;
Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.map, Algo::Render::GL1::LINE, 1.0,
sim.envMap_.position, sim.envMap_.normal) ;
glColor3f(1,0,0);
Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.mapScenary, Algo::Render::GL1::LINE,
1.0, sim.envMap_.positionScenary,
sim.envMap_.normalScenary) ;
......@@ -510,9 +511,10 @@ void SocialAgents::cb_redraw()
glPolygonOffset(1.0f, 1.0f) ;
Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.map, Algo::Render::GL1::LINE, 1.0,
sim.envMap_.position, sim.envMap_.normal) ;
// Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.mapScenary, Algo::Render::GL1::LINE,
// 1.0, sim.envMap_.positionScenary,
// sim.envMap_.normalScenary) ;
glColor3f(1.0f, 0.0f, 0.0f) ;
Algo::Render::GL1::renderTriQuadPoly<PFP>(sim.envMap_.mapScenary, Algo::Render::GL1::LINE,
1.0, sim.envMap_.positionScenary,
sim.envMap_.normalScenary) ;
}
// glColor3f(1.0f, 1.0f, 0.0f);
// glLineWidth(5.0f);
......
......@@ -22,7 +22,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
......@@ -36,14 +36,14 @@
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1680"
inkscape:window-height="1021"
inkscape:window-height="994"
id="namedview20587"
showgrid="false"
inkscape:zoom="3.6203869"
inkscape:cx="869.93163"
inkscape:cy="799.83298"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:zoom="1.8101935"
inkscape:cx="455.54369"
inkscape:cy="1150.26"
inkscape:window-x="1680"
inkscape:window-y="27"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<defs
......@@ -14898,12 +14898,6 @@
id="path5574" />
</clipPath>
</defs>
<path
style="fill:#f0eee8;fill-opacity:1;fill-rule:nonzero;stroke:none"
d="m 40467.855,-218363.05 105489.365,0 -52744.682,79117.02 z"
id="path5583"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
<path
style="fill:#a8a8a8;fill-opacity:0.9;fill-rule:nonzero;stroke:#0f0f0f;stroke-width:0.30000001;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
d="m 252.89062,249.78906 -0.6914,-1.05078 3.91406,-2.96094 -4.32422,-5.9414 -0.48047,0.33593 -2.53125,-3.57812 12.8086,-9.34375 2.94922,3.96875 8.76562,-6.5 -1.57422,-2.29688 0.8711,-0.57812 1.74218,2.18359 5.6875,-4.21875 -1.59375,-2.07812 1.08985,-0.83203 1.57422,2.10156 5.29296,-3.90625 -1.5625,-2.09766 1.08985,-0.85156 1.60547,2.03516 5.84765,-4.26172 -0.68359,-2.84375 1.28125,-0.23047 0.73437,2.875 5.87891,0.92578 1.71094,-2.4375 1.08203,0.51563 -1.22656,2.625 3.63281,5.03906 2.95703,-0.7461 0.21094,1.23829 -2.9375,0.80859 -1.74219,6.28906 2.53906,1.77344 -0.67187,1.00781 -2.58203,-1.29297 -5.63672,4.30469 1.53125,2.12109 -1.1211,0.79688 -1.5664,-2.01563 -5.4375,4.09375 1.7539,2.19532 -6.60546,5.15234 20.53515,27.16016 6.53906,-4.94532 12.37891,16.17579 -11.52734,8.48437 16.36718,24.19531 -24.13671,17.625 -1.91016,0.47266 -1.77344,-0.27344 -1.89062,-0.92187 -15,-20.4375 -5.46094,4.15625 -12.375,-16.78516 6.64453,-4.96875 -28.15234,-37.70703 z"
......@@ -16590,18 +16584,6 @@
id="path7145"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccccccccccc" />
<path
style="fill:#baa8a8;fill-opacity:0.9;fill-rule:nonzero;stroke:#330066;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
d="m 760.53906,865.82422 10.71094,10.71094 -13.82813,13.24609 -8.34375,8 -10.64453,-10.36328 z"
id="path7147"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#baa8a8;fill-opacity:0.9;fill-rule:nonzero;stroke:#330066;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
d="m 738.43359,887.41797 10.64453,10.36328 -11.51562,11.51562 -10.27734,10.26563 -10.50782,-11.04297 z"
id="path7149"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
<path
style="fill:#baa8a8;fill-opacity:0.9;fill-rule:nonzero;stroke:#330066;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
d="m 1139.625,169.89062 0.9414,0.35547 7.3906,-22.45312 -1.4882,-0.54688 1.3203,-3.97656 1.082,0.46094 0.3477,0.3164 15.125,5.01563 -4.0508,12.03125 -4.9219,14.67578 -16.082,-4.94531 z"
......@@ -17036,7 +17018,7 @@
sodipodi:nodetypes="ccccccc" />
<path
style="fill:#baa8a8;fill-opacity:0.9;fill-rule:nonzero;stroke:#330066;stroke-width:0.2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1"
d="m 251.80078,141.60937 6.55078,14.33985 5.40625,11.89453 -12.44922,6.44531 -5.90234,-13.12109 -1.67969,-11.14844 -1.74219,-3.58203 z"
d="m 248.60078,143.20937 6.55078,14.33985 5.40625,11.89453 -12.44922,6.44531 -5.90234,-13.12109 -1.67969,-11.14844 -1.74219,-3.58203 z"
id="path7325"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccc" />
......@@ -36,14 +36,14 @@
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1680"
inkscape:window-height="994"
inkscape:window-height="1021"
id="namedview20587"
showgrid="false"
inkscape:zoom="1.8101934"
inkscape:cx="1224.7448"
inkscape:cy="253.83295"
inkscape:window-x="1680"
inkscape:window-y="27"
inkscape:cx="1196.5556"
inkscape:cy="234.69695"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg2"
inkscape:object-nodes="true"
......@@ -15064,10 +15064,10 @@
sodipodi:nodetypes="ccccccccccccccccccscccc" />
<path
style="fill:none;stroke:#bababa;stroke-width:16;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
d="m 977.6,939.4 c -20.57401,4.70041 -44.5378,5.76895 -60.56875,16.49453 L 767.85547,1105.918"
d="M 917.03125,955.89453 767.85547,1105.918"
id="path6315"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#bababa;stroke-width:16;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
d="M 560.98047,901.38281 572.72656,906 l 8.70313,8.80859 8.6914,8.87891 21.88672,22.36328 8.50391,5.24609 16.11328,1.73438 55.74219,6.02344 9.1875,-1.83594 6.27734,-2.84375 6.01563,-4.11719 65.14843,-100.5039"
......@@ -15192,7 +15192,7 @@
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#bababa;stroke-width:16;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1"
d="m 917.03125,955.89453 c 6.4106,-13.62585 -4.68488,-24.28891 -14.65625,-29.85547"
d="m 917.03125,955.89453 c 6.4106,-13.62585 19.18621,-17.55844 9.21484,-23.125"
id="path6383"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment