diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index 9ca72c5e463d9d11de03aca1af3fb1c0e4cdfae1..6148950d7fa6c195a6f08220a760641172b5d1b4 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -150,6 +150,44 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, } } } + else if (qName == "source") + { + double xmin, xmax, ymin, ymax; + double z=0;// @todo read this some when we go 3D + + int source_id=-1; + for(int i=0; i<at.length(); i++) { + if(at.localName(i)=="id") { + source_id=at.value(i).toInt(); + } else if(at.localName(i)=="x_min") { + xmin=at.value(i).toDouble()*FAKTOR; + } + else if(at.localName(i)=="x_max") { + xmax=at.value(i).toDouble()*FAKTOR; + } + else if(at.localName(i)=="y_min") { + ymin=at.value(i).toDouble()*FAKTOR; + } + else if(at.localName(i)=="y_max") { + ymax=at.value(i).toDouble()*FAKTOR; + } + } + _geometry->addSource(xmin,ymin,xmax,ymax); + + // double CHT[3]= {_color,_height,_thickness}; + // JPoint* pt1= new JPoint(xmin,ymin,z); + // JPoint* pt2= new JPoint(xmin,ymax,z); + // JPoint* pt3= new JPoint(xmax,ymin,z); + // JPoint* pt4= new JPoint(xmax,ymax,z); + // pt1->setColorHeightThicknes(CHT); + // pt2->setColorHeightThicknes(CHT); + // pt3->setColorHeightThicknes(CHT); + // pt4->setColorHeightThicknes(CHT); + // _currentPointsList.push_back(pt1); + // _currentPointsList.push_back(pt2); + // _currentPointsList.push_back(pt3); + // _currentPointsList.push_back(pt4); + } // source } else if (qName == "floor") { double xMin=0, xMax=0, @@ -423,17 +461,17 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, double el_z=std::numeric_limits<double>::quiet_NaN(); for(int i=0; i<at.length(); i++) { - if(at.localName(i)=="ID") { - id=at.value(i).toInt(); - //TODO: maybe you should change ur format to take the ID 0 as first valid ID. - if (id==0) { - //slotErrorOutput("Person with ID=0 detected. ID should start with 1 !"); - return false; - } - } else if(at.localName(i)==_jps_xPos) { - xPos=at.value(i).toDouble()*FAKTOR; - //xPos=at.value(i).toDouble(); - } else if(at.localName(i)==_jps_yPos) { + if(at.localName(i)=="ID") { + id=at.value(i).toInt(); + //TODO: maybe you should change ur format to take the ID 0 as first valid ID. + if (id==0) { + //slotErrorOutput("Person with ID=0 detected. ID should start with 1 !"); + return false; + } + } else if(at.localName(i)==_jps_xPos) { + xPos=at.value(i).toDouble()*FAKTOR; + //xPos=at.value(i).toDouble(); + } else if(at.localName(i)==_jps_yPos) { //yPos=at.value(i).toDouble(); yPos=at.value(i).toDouble()*FAKTOR; } else if(at.localName(i)==_jps_zPos) { diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index 3ecb786dfae33be1ecec62cedccca9ea1d8aa917..09bee37b1b697578ab8b9f0438461c959a3d067f 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -195,9 +195,9 @@ void FacilityGeometry::addNewElement(double center[3], double length, double ori actor->GetProperty()->SetAmbient(0.2); actor->GetProperty()->SetDiffuse(0.8); - // double data[3]; - // actor->GetPosition(data); - // actor->SetPosition(data[0],data[1],src->GetZLength()/2); + // double data[3]; + // actor->GetPosition(data); + // actor->SetPosition(data[0],data[1],src->GetZLength()/2); switch (type) { case DOOR: { @@ -573,6 +573,69 @@ void FacilityGeometry::addObstacles(vtkPolyData* polygonPolyData ) assembly3D->AddPart(obstaclesActor); } + + +void FacilityGeometry::addSource(double x1, double y1, double x2, double y2, double z) +{ + //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); + + double color[2][3]= {{120, 120, 120},{150,150,150}}; + 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); + imageActor->GetProperty()->SetAmbient(0.2); + //imageActor->GetProperty()->SetDiffuse(0.8); + + // move the actor in x-direction + imageActor->SetPosition(x1, y1, z); + assembly2D->AddPart(imageActor); + +} + + void FacilityGeometry::addFloor(double x1, double y1, double x2, double y2, double z) { //if(z!=1)return; diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h index 9b9cff255c54fd113b09d9e67b81d731aca999e5..9a100197d5befe5043920f4d16c5f0fb6e7921c0 100644 --- a/src/geometry/FacilityGeometry.h +++ b/src/geometry/FacilityGeometry.h @@ -104,6 +104,7 @@ public: /// draw a floor, divided in cells, void addFloor(double x1, double y1, double x2, double y2, double z=0); + void addSource(double x1, double y1, double x2, double y2, double z=0); void addFloor(vtkPolyData* polygonPolyData); ///draw obstacles