FacilityGeometry.cpp 26.4 KB
Newer Older
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/**
 * @file FacilityGeometry.cpp
 * @author   Ulrich Kemloh <kemlohulrich@gmail.com>
 * @version 0.1
 * Copyright (C) <2009-2010>
 *
 *
 * @section LICENSE
 * This file is part of OpenPedSim.
 *
 * OpenPedSim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * OpenPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
 * @section DESCRIPTION
 *
 * @brief method for plotting the different geometry/Building elements
 *
 *  Created on: 07.05.2009
 *
 */

#include "FacilityGeometry.h"
33
#include "JPoint.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include "../SystemSettings.h"
#include "LinePlotter2D.h"

#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkAssembly.h>
#include <vtkCylinderSource.h>
#include <vtkSphereSource.h>
#include <vtkDiskSource.h>
#include <vtkCubeSource.h>
#include <vtkDataSetMapper.h>
#include <vtkLookupTable.h>
#include <vtkCellData.h>
#include <vtkPointData.h>
#include <vtkImageData.h>
#include <vtkProp3DCollection.h>
#include <vtkSmartPointer.h>

#include <vtkCaptionRepresentation.h>
#include <vtkCaptionActor2D.h>
#include <vtkTextActor.h>
#include <vtkCaptionWidget.h>
#include <vtkTextActor3D.h>
#include <vtkTextProperty.h>
#include <vtkActor2DCollection.h>
60
#include <vtkTriangleFilter.h>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
61

62

Ulrich Kemloh's avatar
Ulrich Kemloh committed
63 64 65 66 67
#define PI 3.1415926535

using namespace std;

#define VTK_CREATE(type, name) \
68
    vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
Ulrich Kemloh's avatar
Ulrich Kemloh committed
69 70


71
FacilityGeometry::FacilityGeometry(const string &description, const string &roomCaption, const string &subroomCaption)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
72
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
73

74 75 76
    assembly = vtkAssembly::New();
    assembly2D = vtkAssembly::New();
    assemblyCaptions= vtkAssembly::New();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
77

78 79 80
    assemblyWalls3D = vtkAssembly::New();
    assemblyDoors3D = vtkAssembly::New();
    assembly3D = vtkAssembly::New();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
81

82
    floorActor = vtkActor::New();
83
    obstaclesActor = vtkActor::New();
84
    gradientFieldActor = vtkActor::New();
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

    captions=vtkActor2DCollection::New();
    linesPlotter2D = new LinePlotter2D();

    // initializing the lookup table for the colors
    // rainbow colors ranging from red to blue
    lookupTable =  vtkLookupTable::New();
    lookupTable->SetTableRange(0,255);
    //lookupTable->SetHueRange(0.0,0.566);
    //lut->SetSaturationRange(0,0);
    //lut->SetValueRange(0.0,1.0);
    lookupTable->SetNumberOfTableValues(256);
    lookupTable->Build();

    // geometry parameters all in cm
    doorThickness = 3;
    wallThickness = 3;
    wallHeight=250;
    doorHeight=250;
    stepHeight = 40;
    wallColor = 255;
    stepColor = 130;
    doorColor = 50;
108
    navlineColor=95;
109
    _description=description;
110 111
    _roomCaption=roomCaption;
    _subroomCaption=subroomCaption;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
112 113
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
114 115
FacilityGeometry::~FacilityGeometry()
{
116
    lookupTable->Delete();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
117 118 119 120 121 122 123 124 125 126
    captions->Delete();

    assembly->Delete();
    assembly2D->Delete();
    assemblyCaptions->Delete();

    assemblyWalls3D->Delete();
    assemblyDoors3D->Delete();
    assembly3D->Delete();
    floorActor->Delete();
127
    obstaclesActor->Delete();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
128

129
    delete linesPlotter2D;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
130 131
}

132 133 134 135
vtkAssembly* FacilityGeometry::getActor2D()
{
    return assembly2D;
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
136

137 138 139 140
vtkAssembly* FacilityGeometry::getCaptionsActor()
{
    return assemblyCaptions;
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
141

142 143 144
vtkAssembly* FacilityGeometry::getActor3D()
{
    return assembly3D;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
145 146
}

147 148 149 150
void FacilityGeometry::CreateActors()
{
    assembly2D->AddPart(linesPlotter2D->createAssembly());
    assembly2D->AddPart(assemblyCaptions);
151

152 153 154 155
    assembly3D->AddPart(assemblyDoors3D);
    assembly3D->AddPart(assemblyWalls3D);
    assembly3D->AddPart(assemblyCaptions);
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
156

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
void FacilityGeometry::setVisibility(bool status)
{
    if(SystemSettings::get2D())
    {
        assembly2D->SetVisibility(status);
    }
    else
    {
        assembly3D->SetVisibility(status);
    }
    _visibility=status;
}

bool FacilityGeometry::getVisibility() const
{
    return _visibility;
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
174 175
/***
 * This is the main build method and should be called by all functions
176
 * drawing a wall or a door. Important
Ulrich Kemloh's avatar
Ulrich Kemloh committed
177
 */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
178 179
void FacilityGeometry::addNewElement(double center[3], double length, double orientation, ELEMENT_TYPE type)
{
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

    vtkCubeSource* src = vtkCubeSource::New();
    src->SetCenter(center[0],center[1],center[2]);
    src->SetYLength(length);

    vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
    mapper->SetInputConnection(src->GetOutputPort());
    src->Delete();

    vtkActor* actor = vtkActor::New();
    actor->SetMapper(mapper);
    mapper->Delete();
    actor->GetProperty()->SetLighting(true);
    actor->SetOrigin(center[0],center[1],center[2]);
    actor->RotateZ(orientation);
    actor->GetProperty()->SetAmbient(0.2);
    actor->GetProperty()->SetDiffuse(0.8);

Mohcine Chraibi's avatar
Mohcine Chraibi committed
198 199 200
    //  double data[3];
    //  actor->GetPosition(data);
    //  actor->SetPosition(data[0],data[1],src->GetZLength()/2);
201

Ulrich Kemloh's avatar
Ulrich Kemloh committed
202 203
    switch (type) {
    case DOOR: {
204 205 206 207 208 209
        double colorRGB[3];
        lookupTable->GetColor(doorColor, colorRGB);
        actor->GetProperty()->SetColor(colorRGB);
        src->SetXLength(doorThickness);
        src->SetZLength(doorHeight);
        //src->SetRadius(doorWidth);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
210
        actor->GetProperty()->SetOpacity(0.5);
211 212
        assemblyDoors3D->AddPart(actor);
    }
213
        break;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
214
    case WALL: {
215 216 217 218 219 220 221 222 223 224 225 226
        double colorRGB[3];
        lookupTable->GetColor(wallColor, colorRGB);
        actor->GetProperty()->SetColor(colorRGB);
        //actor->GetProperty()->SetSpecular(1);
        //actor->GetProperty()->SetDiffuse(1);
        //actor->GetProperty()->SetAmbient(1);

        src->SetXLength(wallThickness);
        src->SetZLength(wallHeight);
        //src->SetRadius(wallWidth);
        assemblyWalls3D->AddPart(actor);
    }
227
        break;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
228
    case STEP: {
229 230 231 232 233 234 235
        double colorRGB[3];
        lookupTable->GetColor(stepColor, colorRGB);
        actor->GetProperty()->SetColor(colorRGB);
        src->SetXLength(wallThickness); //FIXME, this is wrong
        src->SetZLength(stepHeight);
        assemblyDoors3D->AddPart(actor);
    }
236
        break;
237

238
        //default behaviour not defined
239 240 241 242 243 244 245 246 247 248
    default:
        break;
    }

    // now adjusting the z coordinates
    double data[3];
    actor->GetPosition(data);
    actor->SetPosition(data[0],data[1],src->GetZLength()/2);
    actor->Delete();
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
249

Ulrich Kemloh's avatar
Ulrich Kemloh committed
250 251
void FacilityGeometry::addWall(double x1, double y1, double z1, double x2, double y2, double z2,double thickness,double height,double color)
{
252 253
    // all walls will have this parameters until changed
    wallColor=color;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
254

255
    //	if(SystemSettings::get2D()){
Ulrich Kemloh's avatar
Ulrich Kemloh committed
256 257
    double m[]= {x1,y1,z1};
    double n[]= {x2,y2,z2};
258
    linesPlotter2D->PlotWall(m,n,wallColor/255.0);
259 260 261 262


    JPoint *p1 = new JPoint(x1,y1,z1);
    JPoint *p2 = new JPoint(x2,y2,z2);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
263 264
    JPoint p3 =p1->centreCoordinatesWith(*p2);
    double centre[3]; p3.getXYZ(centre);
265 266 267
    double angle =p1->angleMadeWith(*p2);
    double length =p1->distanceTo(*p2)+wallThickness;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
268
    addNewElement(centre, length, angle, WALL);
269 270 271

    delete p1;
    delete p2;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
272 273
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
274 275
void FacilityGeometry::addStair(double x1, double y1, double z1, double x2, double y2, double z2,double thickness,double height,double color)
{
276 277 278 279 280

    // all walls will have this parameters until changed
    wallColor=color;

    //	if(SystemSettings::get2D()){
Ulrich Kemloh's avatar
Ulrich Kemloh committed
281 282
    double m[]= {x1,y1,z1};
    double n[]= {x2,y2,z2};
283 284 285
    linesPlotter2D->PlotWall(m,n,wallColor/255.0);


286 287 288 289 290
    //    JPoint *p1 = new JPoint(x1,y1,z1);
    //    JPoint *p2 = new JPoint(x2,y2,z2);
    //    double *center = p1->centreCoordinatesWith(*p2);
    //    double angle =p1->angleMadeWith(*p2);
    //    double length =p1->distanceTo(*p2)+wallThickness;
291

292
    //    addNewElement(center, length, angle, WALL);
293

294 295 296
    //    delete p1;
    //    delete p2;
    //    delete center;
297 298
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
299 300
void FacilityGeometry::addDoor(double x1, double y1, double z1, double x2, double y2, double z2,double thickness ,double height, double color)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
301

302 303 304 305
    // all doors will take this color upon changed
    doorColor=color;
    //constructing the 2D assembly
    //	if(SystemSettings::get2D()){
Ulrich Kemloh's avatar
Ulrich Kemloh committed
306 307
    double m[]= {x1,y1,z1};
    double n[]= {x2,y2,z2};
Ulrich Kemloh's avatar
Ulrich Kemloh committed
308

309
    linesPlotter2D->PlotDoor(m,n,doorColor/255.0);
310 311 312

    JPoint *p1 = new JPoint(x1,y1,z1);
    JPoint *p2 = new JPoint(x2,y2,z2);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
313 314
    JPoint p3 =p1->centreCoordinatesWith(*p2);
    double centre[3]; p3.getXYZ(centre);
315 316 317
    double angle =p1->angleMadeWith(*p2);
    double length =p1->distanceTo(*p2)+wallThickness;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
318
    addNewElement(centre, length, angle, DOOR);
319 320 321

    delete p1;
    delete p2;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
322

323 324
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
325 326
void FacilityGeometry::addNavLine(double x1, double y1, double z1, double x2, double y2, double z2,double thickness ,double height, double color)
{
327 328 329 330 331

    // all doors will take this color upon changed
    navlineColor=color;
    //constructing the 2D assembly
    //	if(SystemSettings::get2D()){
Ulrich Kemloh's avatar
Ulrich Kemloh committed
332 333
    double m[]= {x1,y1,z1};
    double n[]= {x2,y2,z2};
334 335 336

    linesPlotter2D->PlotNavLine(m,n,navlineColor/255.0);

337 338 339 340 341
    //    JPoint *p1 = new JPoint(x1,y1,z1);
    //    JPoint *p2 = new JPoint(x2,y2,z2);
    //    double *center = p1->centreCoordinatesWith(*p2);
    //    double angle =p1->angleMadeWith(*p2);
    //    double length =p1->distanceTo(*p2)+wallThickness;
342

343
    //    addNewElement(center, length, angle, DOOR);
344

345 346 347
    //    delete p1;
    //    delete p2;
    //    delete center;
348 349
}

350 351
void FacilityGeometry::addStep(double x1, double y1, double z1, double x2, double y2, double z2)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
352 353
    double m[]= {x1,y1,z1};
    double n[]= {x2,y2,z2};
354
    linesPlotter2D->PlotDoor(m,n,doorColor/255.0);
355 356 357

    JPoint *p1 = new JPoint(x1,y1,z1);
    JPoint *p2 = new JPoint(x2,y2,z2);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
358 359
    JPoint p3 =p1->centreCoordinatesWith(*p2);
    double centre[3]; p3.getXYZ(centre);
360 361 362
    double angle =p1->angleMadeWith(*p2);
    double length =p1->distanceTo(*p2)+wallThickness;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
363
    addNewElement(centre, length, angle, STEP);
364 365 366

    delete p1;
    delete p2;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
367

Ulrich Kemloh's avatar
Ulrich Kemloh committed
368 369
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
370 371
void FacilityGeometry::addStep(JPoint* p1, JPoint* p2)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
372

373 374 375
    double m[3];
    double n[3];
    double CHT[3];
Ulrich Kemloh's avatar
Ulrich Kemloh committed
376

377 378 379
    p1->getXYZ(m);
    p2->getXYZ(n);
    p1->getColorHeightThicknes(CHT);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
380

381 382
    stepHeight=CHT[1];
    stepColor = CHT[0];
Ulrich Kemloh's avatar
Ulrich Kemloh committed
383

384
    linesPlotter2D->PlotDoor(m,n,doorColor/255.0);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
385

Ulrich Kemloh's avatar
Ulrich Kemloh committed
386 387
    JPoint p3 =p1->centreCoordinatesWith(*p2);
    double centre[3]; p3.getXYZ(centre);
388 389
    double angle =p1->angleMadeWith(*p2);
    double length =p1->distanceTo(*p2)+wallThickness;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
390
    addNewElement(centre,  length, angle,  STEP);
391

392
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
393

Ulrich Kemloh's avatar
Ulrich Kemloh committed
394 395
void FacilityGeometry::addWall(JPoint* p1, JPoint* p2, string caption)
{
396 397 398 399 400 401 402 403 404 405 406 407
    double m[3];
    double n[3];
    double CHT[3];
    p1->getXYZ(m);
    p2->getXYZ(n);
    p1->getColorHeightThicknes(CHT);

    wallThickness = CHT[2];
    wallHeight=CHT[1];
    wallColor = CHT[0];
    linesPlotter2D->PlotWall(m,n,wallColor/255.0);

Ulrich Kemloh's avatar
Ulrich Kemloh committed
408
    if (caption.compare("") != 0) {
409 410 411 412 413

        double center[3];
        center[0]=0.5*(m[0]+n[0]);
        center[1]=0.5*(m[1]+n[1]);
        center[2]=0.5*(m[2]+n[2]);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
414
        double orientation[3]= {0,0,0};
415 416 417
        addNewElementText(center,orientation,caption.c_str(),50);
    }

Ulrich Kemloh's avatar
Ulrich Kemloh committed
418 419
    JPoint p3 =p1->centreCoordinatesWith(*p2);
    double centre[3]; p3.getXYZ(centre);
420 421
    double angle =p1->angleMadeWith(*p2);
    double length =p1->distanceTo(*p2)+wallThickness;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
422
    addNewElement( centre,  length, angle,  WALL);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
423 424
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
425 426
void FacilityGeometry::addStair(JPoint* p1, JPoint* p2, string caption)
{
427 428 429 430 431 432 433 434 435 436 437 438
    double m[3];
    double n[3];
    double CHT[3];
    p1->getXYZ(m);
    p2->getXYZ(n);
    p1->getColorHeightThicknes(CHT);

    wallThickness = CHT[2];
    wallHeight=CHT[1];
    wallColor = CHT[0];
    linesPlotter2D->PlotWall(m,n,wallColor/255.0);

Ulrich Kemloh's avatar
Ulrich Kemloh committed
439
    if (caption.compare("") != 0) {
440 441 442 443 444

        double center[3];
        center[0]=0.5*(m[0]+n[0]);
        center[1]=0.5*(m[1]+n[1]);
        center[2]=0.5*(m[2]+n[2]);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
445
        double orientation[3]= {0,0,0};
446 447 448
        addNewElementText(center,orientation,caption.c_str(),50);
    }

449 450 451 452
    //    double *center = p1->centreCoordinatesWith(*p2);
    //    double angle =p1->angleMadeWith(*p2);
    //    double length =p1->distanceTo(*p2)+wallThickness;
    //    addNewElement( center,  length, angle,  WALL);
453 454
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
455 456
void FacilityGeometry::addDoor(JPoint* p1, JPoint* p2, string caption)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
457

458 459 460
    double m[3];
    double n[3];
    double CHT[3];
Ulrich Kemloh's avatar
Ulrich Kemloh committed
461

462 463 464 465 466 467
    p1->getXYZ(m);
    p2->getXYZ(n);
    //to get the exits over the walls
    //m[0]++;	m[1]++;	m[2]++;
    //n[0]++;	n[1]++;	n[2]++;
    p1->getColorHeightThicknes(CHT);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
468

469 470 471
    doorThickness = CHT[2];
    doorHeight=CHT[1];
    doorColor = CHT[0];
Ulrich Kemloh's avatar
Ulrich Kemloh committed
472

473
    linesPlotter2D->PlotDoor(m,n,doorColor/255.0);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
474

Ulrich Kemloh's avatar
Ulrich Kemloh committed
475
    if (caption.compare("") != 0) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
476

477 478 479 480
        double center[3];
        center[0]=0.5*(m[0]+n[0]);
        center[1]=0.5*(m[1]+n[1]);
        center[2]=0.5*(m[2]+n[2]);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
481
        double orientation[3]= {0,0,0};
482 483
        addNewElementText(center,orientation,caption.c_str(),0);
    }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
484

Ulrich Kemloh's avatar
Ulrich Kemloh committed
485 486
    JPoint p3 =p1->centreCoordinatesWith(*p2);
    double centre[3]; p3.getXYZ(centre);
487 488
    double angle =p1->angleMadeWith(*p2);
    double length =p1->distanceTo(*p2)+wallThickness;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
489
    addNewElement( centre,  length, angle,  DOOR);
490
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
491

Ulrich Kemloh's avatar
Ulrich Kemloh committed
492 493
void FacilityGeometry::addNavLine(JPoint* p1, JPoint* p2, string caption)
{
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511

    double m[3];
    double n[3];
    double CHT[3];

    p1->getXYZ(m);
    p2->getXYZ(n);
    //to get the exits over the walls
    //m[0]++;	m[1]++;	m[2]++;
    //n[0]++;	n[1]++;	n[2]++;
    p1->getColorHeightThicknes(CHT);

    doorThickness = CHT[2];
    doorHeight=CHT[1];
    doorColor = CHT[0];

    linesPlotter2D->PlotNavLine(m,n,doorColor/255.0);

Ulrich Kemloh's avatar
Ulrich Kemloh committed
512
    if (caption.compare("") != 0) {
513 514 515 516 517

        double center[3];
        center[0]=0.5*(m[0]+n[0]);
        center[1]=0.5*(m[1]+n[1]);
        center[2]=0.5*(m[2]+n[2]);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
518
        double orientation[3]= {0,0,0};
519 520 521 522
        addNewElementText(center,orientation,caption.c_str(),0);
    }
}

523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
void FacilityGeometry::addFloor(vtkPolyData* polygonPolyData )
{
    //triagulate everything
    // Create a mapper and actor
    VTK_CREATE(vtkTriangleFilter,filter);
    VTK_CREATE(vtkPolyDataMapper,mapper);

#if VTK_MAJOR_VERSION <= 5
    filter->SetInput(polygonPolyData);
    mapper->SetInput(filter->GetOutput());
#else
    filter->SetInputData(polygonPolyData);
    mapper->SetInputConnection(filter->GetOutputPort());
#endif

    floorActor->SetMapper(mapper);
    floorActor->GetProperty()->SetColor(0,0,1);
540
    floorActor->GetProperty()->SetOpacity(0.4);
541 542 543 544 545

    assembly2D->AddPart(floorActor);
    assembly3D->AddPart(floorActor);
}

546 547 548 549 550 551 552
void FacilityGeometry::addGradientField(vtkActor* gradientField)
{
    gradientFieldActor=gradientField;
    assembly2D->AddPart(gradientFieldActor);
    assembly3D->AddPart(gradientFieldActor);
}

553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
void FacilityGeometry::addObstacles(vtkPolyData* polygonPolyData )
{
    //triagulate everything
    // Create a mapper and actor
    VTK_CREATE(vtkTriangleFilter,filter);
    VTK_CREATE(vtkPolyDataMapper,mapper);

#if VTK_MAJOR_VERSION <= 5
    filter->SetInput(polygonPolyData);
    mapper->SetInput(filter->GetOutput());
#else
    filter->SetInputData(polygonPolyData);
    mapper->SetInputConnection(filter->GetOutputPort());
#endif

    obstaclesActor->SetMapper(mapper);
    obstaclesActor->GetProperty()->SetColor(0.4,0.4,0.4);
    obstaclesActor->GetProperty()->SetOpacity(0.5);

    assembly2D->AddPart(obstaclesActor);
    assembly3D->AddPart(obstaclesActor);
}
575

Mohcine Chraibi's avatar
Mohcine Chraibi committed
576 577


578
void FacilityGeometry::addRectangle(double x1, double y1, double x2, double y2, double z, double color1, double color2, string text)
Mohcine Chraibi's avatar
Mohcine Chraibi committed
579 580
{
    //if(z!=1)return;
581
     const double cellSize=10; //cm
Mohcine Chraibi's avatar
Mohcine Chraibi committed
582 583
    //	const int dimX=(x2-x1)/cellSize+1;
    //	const int dimY=(y2-y1)/cellSize+1;
584

Mohcine Chraibi's avatar
Mohcine Chraibi committed
585 586 587 588 589 590 591 592
    const int dimX= (int)ceil((x2-x1)/cellSize) +1;
    const int dimY= (int)ceil((y2-y1)/cellSize) +1;


    const int dimZ=1;
    //vtkDoubleArray *scalars = vtkDoubleArray::New();
    vtkDataArray* pData = vtkUnsignedCharArray::New();
    pData->SetNumberOfComponents(3);
593
    double color[2][3]= {{color1, color1, color1},{color2,color2,color2}};
Mohcine Chraibi's avatar
Mohcine Chraibi committed
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
    bool idx=0;
    bool lastColorUsed=0;
    for(int i=0; i<dimY-1; i++) {

        if(idx==lastColorUsed) {
            lastColorUsed= !lastColorUsed;
            idx=lastColorUsed;
        } else {
            lastColorUsed=idx;
        }

        for(int j=0; j<dimX-1; j++) {
            pData->InsertNextTuple3(color[idx][0],color[idx][1],color[idx][2]);
            idx=!idx;
        }
    }

    // data as cellData of imageData
    VTK_CREATE(vtkImageData, image);
    image->SetDimensions(dimX, dimY, dimZ);
    image->SetSpacing(cellSize, cellSize, cellSize);
    image->GetCellData()->SetScalars(pData);


    VTK_CREATE(vtkActor, imageActor);
    VTK_CREATE(vtkDataSetMapper, map);

#if VTK_MAJOR_VERSION <= 5
    map->SetInput(image);
#else
    map->SetInputData(image);
#endif

    //map->SetLookupTable(lookupTable);
    imageActor->SetMapper(map);
629 630 631 632
    if(color2==90) // quick and dirty --> goal
         imageActor->GetProperty()->SetAmbient(1.5);
    else
         imageActor->GetProperty()->SetAmbient(0.6);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
633 634 635 636 637
    //imageActor->GetProperty()->SetDiffuse(0.8);

    // move the actor in x-direction
    imageActor->SetPosition(x1, y1, z);
    assembly2D->AddPart(imageActor);
638 639
    double center[3]={x1/2+x2/2, y1/2+y2/2, 0};
    addNewElementText(center, 0, text, 0);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
640 641 642 643

}


Ulrich Kemloh's avatar
Ulrich Kemloh committed
644 645
void FacilityGeometry::addFloor(double x1, double y1, double x2, double y2, double z)
{
646 647 648 649 650 651 652 653 654 655 656 657 658
    //if(z!=1)return;
    const double cellSize=40; //cm
    //	const int dimX=(x2-x1)/cellSize+1;
    //	const int dimY=(y2-y1)/cellSize+1;
    const int dimX= (int)ceil((x2-x1)/cellSize) +1;
    const int dimY= (int)ceil((y2-y1)/cellSize) +1;


    const int dimZ=1;
    //vtkDoubleArray *scalars = vtkDoubleArray::New();
    vtkDataArray* pData = vtkUnsignedCharArray::New();
    pData->SetNumberOfComponents(3);

Ulrich Kemloh's avatar
Ulrich Kemloh committed
659
    double color[2][3]= {{100, 100, 100},{150,150,150}};
660 661
    bool idx=0;
    bool lastColorUsed=0;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
662
    for(int i=0; i<dimY-1; i++) {
663

Ulrich Kemloh's avatar
Ulrich Kemloh committed
664
        if(idx==lastColorUsed) {
665 666
            lastColorUsed= !lastColorUsed;
            idx=lastColorUsed;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
667
        } else {
668 669 670
            lastColorUsed=idx;
        }

Ulrich Kemloh's avatar
Ulrich Kemloh committed
671
        for(int j=0; j<dimX-1; j++) {
672 673 674 675 676 677 678 679 680 681 682 683 684 685
            pData->InsertNextTuple3(color[idx][0],color[idx][1],color[idx][2]);
            idx=!idx;
        }
    }

    // data as cellData of imageData
    VTK_CREATE(vtkImageData, image);
    image->SetDimensions(dimX, dimY, dimZ);
    image->SetSpacing(cellSize, cellSize, cellSize);
    image->GetCellData()->SetScalars(pData);


    VTK_CREATE(vtkActor, imageActor);
    VTK_CREATE(vtkDataSetMapper, map);
686 687 688 689

#if VTK_MAJOR_VERSION <= 5
    map->SetInput(image);
#else
690
    map->SetInputData(image);
691 692
#endif

693 694 695 696
    //map->SetLookupTable(lookupTable);
    imageActor->SetMapper(map);
    imageActor->GetProperty()->SetAmbient(0.2);
    //imageActor->GetProperty()->SetDiffuse(0.8);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
697

698 699 700
    // move the actor in x-direction
    imageActor->SetPosition(x1, y1, z);
    assembly2D->AddPart(imageActor);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
701 702 703 704 705

}


void FacilityGeometry::addObjectSphere(double center[3], double radius,
706
double color)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
707
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
708

709 710
    double colorRGB[3];
    lookupTable->GetColor(color, colorRGB);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
711

712 713 714 715 716 717
    //create a disk for the 2D world
    {
        VTK_CREATE(vtkDiskSource, disk);
        disk->SetCircumferentialResolution(10);
        disk->SetInnerRadius(0);
        disk->SetOuterRadius(radius);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
718

719 720
        VTK_CREATE(vtkPolyDataMapper, mapper);
        mapper->SetInputConnection(disk->GetOutputPort());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
721

722 723 724
        VTK_CREATE(vtkActor, actor);
        actor->SetMapper(mapper);
        actor->GetProperty()->SetColor(colorRGB);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
725

726 727 728
        actor->SetPosition(center[0], center[1], center[2]);
        assembly2D->AddPart(actor);
    }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
729 730 731 732
}


void FacilityGeometry::addObjectCylinder(double center[3], double radius,
733
double height, double orientation[3],double color)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
734
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
735

736 737
    double colorRGB[3];
    lookupTable->GetColor(color, colorRGB);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
738

739 740 741 742 743 744 745
    //create a disk for the 2D world
    //TODO: this is of course a wrong projection
    {
        VTK_CREATE(vtkDiskSource, disk);
        disk->SetCircumferentialResolution(10);
        disk->SetInnerRadius(0);
        disk->SetOuterRadius(radius);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
746

747 748
        VTK_CREATE(vtkPolyDataMapper, mapper);
        mapper->SetInputConnection(disk->GetOutputPort());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
749

750 751 752
        VTK_CREATE(vtkActor, actor);
        actor->SetMapper(mapper);
        actor->GetProperty()->SetColor(colorRGB);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
753

754 755 756
        actor->SetPosition(center[0], center[1], center[2]);
        assembly2D->AddPart(actor);
    }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
757 758 759
}

void FacilityGeometry::addObjectBox(double center[3], double height,
760
double width, double length, double color)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
761
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
762

763 764
    double colorRGB[3];
    lookupTable->GetColor(color, colorRGB);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
765

766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
    {
        VTK_CREATE(vtkCubeSource,src);
        src->SetCenter(center[0], center[1], center[2]);
        src->SetZLength(1); //todo: fake projection
        src->SetYLength(length);
        src->SetXLength(width);

        VTK_CREATE(vtkPolyDataMapper,mapper);
        mapper->SetInputConnection(src->GetOutputPort());

        VTK_CREATE(vtkActor,actor);
        actor->GetProperty()->SetLighting(true);
        actor->SetOrigin(center[0], center[1], 0);
        actor->GetProperty()->SetColor(colorRGB);
        actor->GetProperty()->SetAmbient(0.2);
        actor->GetProperty()->SetDiffuse(0.8);
        actor->SetMapper(mapper);
        assembly2D->AddPart(actor);
    }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
785 786
}

787 788 789 790 791 792 793 794 795 796 797
void FacilityGeometry::changeWallsColor(double* color)
{
    //2D part
    linesPlotter2D->changeWallsColor(color);
    assembly2D->Modified();

    //3D parts
    vtkProp3DCollection* col=assemblyWalls3D->GetParts();
    assemblyWalls3D->GetActors(col);

    int count = col->GetNumberOfItems();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
798
    for (int i=0; i<count; i++) {
799 800 801
        ((vtkActor*)col->GetItemAsObject(i))->GetProperty()->SetColor(color);
    }
    assemblyWalls3D->Modified();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
802 803
}

804 805 806 807 808 809 810 811 812
void FacilityGeometry::changeExitsColor(double* color)
{
    //2D part
    linesPlotter2D->changeDoorsColor(color);
    assembly2D->Modified();

    //3D part
    vtkProp3DCollection* col=assemblyDoors3D->GetParts();
    assemblyDoors3D->GetActors(col);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
813

814
    int count = col->GetNumberOfItems();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
815
    for (int i=0; i<count; i++) {
816 817 818
        ((vtkActor*)col->GetItemAsObject(i))->GetProperty()->SetColor(color);
    }
    assemblyDoors3D->Modified();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
819 820 821

}

822 823 824 825 826 827 828
void FacilityGeometry::changeNavLinesColor(double *color)
{
    //2D part
    linesPlotter2D->changeNavLinesColor(color);
    assembly2D->Modified();
}

829 830 831 832 833
void FacilityGeometry::changeFloorColor(double *color)
{
    floorActor->GetProperty()->SetColor(color);
}

834 835 836 837 838
void FacilityGeometry::changeObstaclesColor(double *color)
{
    obstaclesActor->GetProperty()->SetColor(color);
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
839 840
void FacilityGeometry::set2D(bool status)
{
841
    assembly2D->SetVisibility(status);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
842 843
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
844 845
void FacilityGeometry::set3D(bool status)
{
846
    if(assembly3D!=NULL)
847
        assembly3D->SetVisibility(status);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
848 849
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
850 851
void FacilityGeometry::showDoors(bool status)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
852

853 854 855 856 857 858 859
    linesPlotter2D->showDoors(status);
    assembly2D->Modified();

    vtkProp3DCollection* col=assemblyDoors3D->GetParts();
    assemblyDoors3D->GetActors(col);

    int count = col->GetNumberOfItems();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
860
    for (int i=0; i<count; i++) {
861 862 863
        ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status);
    }
    assemblyDoors3D->Modified();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
864 865
}

866 867
void FacilityGeometry::showStairs(bool status)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
868 869 870

}

871 872
void FacilityGeometry::showWalls(bool status)
{
873 874 875 876 877 878 879
    linesPlotter2D->showWalls(status);
    assembly2D->Modified();

    vtkProp3DCollection* col=assemblyWalls3D->GetParts();
    assemblyWalls3D->GetActors(col);

    int count = col->GetNumberOfItems();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
880
    for (int i=0; i<count; i++) {
881 882 883
        ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status);
    }
    assemblyWalls3D->Modified();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
884 885
}

886 887 888 889 890
void FacilityGeometry::showNavLines(bool status)
{
    linesPlotter2D->showNavLines(status);
}

891 892 893 894
void FacilityGeometry::showFloor(bool status)
{
    floorActor->SetVisibility(status);
}
895 896 897 898
void FacilityGeometry::showGradientField(bool status)
{
    gradientFieldActor->SetVisibility(status);
}
899

900 901 902 903
void FacilityGeometry::showObstacles(bool status)
{
    obstaclesActor->SetVisibility(status);
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
904 905
void FacilityGeometry::addObjectLabel(double center[3], double orientation[3], std::string caption, double color)
{
906
    addNewElementText(center, orientation, caption, color);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
907 908
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
909 910
vtkActor2DCollection* FacilityGeometry::getCaptions()
{
911
    return captions;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
912
}
913

914

Ulrich Kemloh's avatar
Ulrich Kemloh committed
915 916
// orientation and color ignored
void FacilityGeometry::addNewElementText(double center[3], double orientation[3],
917
string text, double color)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
918
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
919

920
    //return ;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
921

922 923
    //caption
    VTK_CREATE(vtkTextActor3D,caption);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
924
    //caption = vtkTextActor3D ::New();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
925

926 927 928 929 930 931 932 933 934
    //caption->SetVisibility(false);
    caption->SetInput(text.c_str());
    // set the properties of the caption
    //FARBE
    vtkTextProperty* tprop = caption->GetTextProperty();
    //tprop->SetFontFamilyToArial();
    //tprop->BoldOn();
    //tprop->ShadowOn();
    //tprop->SetLineSpacing(1.0);
935
    tprop->SetFontSize(SystemSettings::getPedestrianCaptionSize()/2);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
936

937 938 939
    double colorRGB[3];
    lookupTable->GetColor(color, colorRGB);
    tprop->SetColor(colorRGB);
940

941 942
    caption->SetPosition(center);
    assemblyCaptions->AddPart(caption);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
943 944 945

}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
946 947
void FacilityGeometry::showGeometryLabels(int status)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
948

949 950
    vtkProp3DCollection* col=assemblyCaptions->GetParts();
    assemblyCaptions->GetActors(col);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
951

952 953
    for (int i=0; i<col->GetNumberOfItems(); i++)
    {
954 955 956
        ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status);
    }
    assemblyCaptions->Modified();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
957 958 959

}

960 961 962 963
const std::string & FacilityGeometry::GetDescription() const
{
    return _description;
}
964 965 966 967 968 969 970 971 972 973 974 975 976 977

const std::string & FacilityGeometry::GetSubRoomCaption() const
{
    return _subroomCaption;
}

const std::string & FacilityGeometry::GetRoomCaption() const
{
    return _roomCaption;
}

void FacilityGeometry::SetRoomCaption(std::string s) {_roomCaption=s; }

void FacilityGeometry::SetSubRoomCaption(std::string s) {_subroomCaption=s; }