546 this->cache =
new PolyDataCache();
557 this->Points = points;
558 this->Colors = colors;
559 this->CellColors->SetNumberOfComponents(colors->GetNumberOfComponents());
564 this->DrawLines(polyData, scalarMode, x, y, scale);
568 this->DrawPolygons(polyData, scalarMode, x, y, scale);
579 struct PolyDataCacheItem
583 std::vector<float> PolyTri;
587 std::vector<float> Lines;
596 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator itPrev = this->PrevFrameCache.begin();
597 for (; itPrev != this->PrevFrameCache.end(); ++itPrev)
599 delete itPrev->second;
602 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator it = this->CurrentFrameCache.begin();
603 for (; it != this->CurrentFrameCache.end(); ++it)
609 PolyDataCacheItem* GetCacheEntry(vtkPolyData* key)
611 PolyDataCacheItem* cacheItem = this->CurrentFrameCache[
key];
612 if (cacheItem ==
nullptr)
614 cacheItem = this->PrevFrameCache[
key];
615 if (cacheItem ==
nullptr)
617 cacheItem =
new PolyDataCacheItem();
624 this->PrevFrameCache.erase(key);
628 this->CurrentFrameCache[
key] = cacheItem;
639 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator itPrev = this->PrevFrameCache.begin();
640 for (; itPrev != this->PrevFrameCache.end(); ++itPrev)
642 delete itPrev->second;
646 this->PrevFrameCache.clear();
649 std::swap(this->PrevFrameCache, this->CurrentFrameCache);
654 std::map<vtkPolyData*, PolyDataCacheItem*> PrevFrameCache;
655 std::map<vtkPolyData*, PolyDataCacheItem*> CurrentFrameCache;
662 float const posX,
float const posY,
float const scale,
vtkIdType cellId,
int scalarMode)
664 this->CellPoints.reserve(this->NumPointsCell * 2);
665 this->CellColors->SetNumberOfTuples(this->NumPointsCell);
666 for (
int i = 0; i < this->NumPointsCell; i++)
669 this->Points->GetPoint(this->PointIds[i], point);
672 float const x =
static_cast<float>(
point[0]) + posX;
673 float const y =
static_cast<float>(
point[1]) + posY;
674 this->CellPoints.push_back(x * scale);
675 this->CellPoints.push_back(y * scale);
682 mappedColorId = this->PointIds[i];
685 mappedColorId = cellId;
688 std::cerr <<
"Scalar mode not supported!" << std::endl;
692 this->CellColors->SetTuple(i, mappedColorId, this->Colors);
702 vtkPolyData* polyData,
int scalarMode,
float const x,
float const y,
float const scale)
704 PolyDataCacheItem* cacheItem = this->cache->GetCacheEntry(polyData);
706 if (polyData->
GetMTime() > cacheItem->LinesLoadingTime)
708 vtkNew<vtkGenericCell> genericCell;
709 cacheItem->Lines.clear();
710 cacheItem->LineColors->Reset();
714 cacheItem->Lines.reserve(numVertices * 2);
715 cacheItem->LineColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
716 cacheItem->LineColors->SetNumberOfTuples(numVertices);
720 vtkCellIterator* cellIter =
nullptr;
728 vtkIdType actualNumPointsCell = genericCell->GetNumberOfPoints();
730 for (
int i = 0; i < actualNumPointsCell - 1; ++i)
732 this->NumPointsCell = 2;
733 this->PointIds = genericCell->GetPointIds()->
GetPointer(i);
735 this->MapCurrentCell(x, y, scale, cellId, scalarMode);
738 for (
int j = 0; j < this->NumPointsCell; j++)
740 cacheItem->Lines.push_back(this->CellPoints[2 * j]);
741 cacheItem->Lines.push_back(this->CellPoints[2 * j + 1]);
743 double* color4 = this->CellColors->GetTuple(j);
744 cacheItem->LineColors->InsertTuple4(
745 vertOffset + j, color4[0], color4[1], color4[2], color4[3]);
748 vertOffset += this->NumPointsCell;
749 this->CellColors->Reset();
750 this->CellPoints.clear();
755 cacheItem->LinesLoadingTime.Modified();
759 if (!cacheItem->Lines.empty())
761 this->Device->DrawLines(cacheItem->Lines.data(),
762 static_cast<int>(cacheItem->Lines.size() / 2),
763 static_cast<unsigned char*
>(cacheItem->LineColors->GetVoidPointer(0)),
764 cacheItem->LineColors->GetNumberOfComponents());
772 vtkIdType GetCountTriangleVertices(vtkPolyData* polyData)
776 vtkNew<vtkGenericCell> genericCell;
777 vtkCellIterator* cellIter =
nullptr;
783 this->NumPointsCell = genericCell->GetNumberOfPoints();
784 this->PointIds = genericCell->GetPointIds()->
GetPointer(0);
785 numTriVert += 3 * (this->NumPointsCell - 2);
798 vtkPolyData* polyData,
int scalarMode,
float const x,
float const y,
float const scale)
800 PolyDataCacheItem* cacheItem = this->cache->GetCacheEntry(polyData);
802 if (polyData->
GetMTime() > cacheItem->PolygonsLoadingTime)
804 cacheItem->PolyTri.clear();
805 cacheItem->PolyColors->Reset();
808 vtkIdType const totalTriVert = this->GetCountTriangleVertices(polyData);
809 cacheItem->PolyTri.reserve(totalTriVert * 2);
810 cacheItem->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
811 cacheItem->PolyColors->SetNumberOfTuples(totalTriVert);
816 cacheItem->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
818 vtkNew<vtkGenericCell> genericCell;
819 vtkCellIterator* cellIter =
nullptr;
828 this->NumPointsCell = genericCell->GetNumberOfPoints();
829 this->PointIds = genericCell->GetPointIds()->
GetPointer(0);
831 this->MapCurrentCell(x, y, scale, cellId, scalarMode);
834 for (
int i = 0; i < this->NumPointsCell - 2; i++)
836 cacheItem->PolyTri.push_back(this->CellPoints[0]);
837 cacheItem->PolyTri.push_back(this->CellPoints[1]);
838 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 2]);
839 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 3]);
840 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 4]);
841 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 5]);
844 vtkIdType const triangOffset = vertOffset + 3 * i;
845 double* color4 = this->CellColors->GetTuple(0);
846 cacheItem->PolyColors->InsertTuple4(
847 triangOffset, color4[0], color4[1], color4[2], color4[3]);
849 color4 = this->CellColors->GetTuple(i + 1);
850 cacheItem->PolyColors->InsertTuple4(
851 triangOffset + 1, color4[0], color4[1], color4[2], color4[3]);
853 color4 = this->CellColors->GetTuple(i + 2);
854 cacheItem->PolyColors->InsertTuple4(
855 triangOffset + 2, color4[0], color4[1], color4[2], color4[3]);
858 vertOffset += 3 * (this->NumPointsCell - 2);
859 this->CellColors->Reset();
860 this->CellPoints.clear();
864 cacheItem->PolygonsLoadingTime.Modified();
868 if (!cacheItem->PolyTri.empty())
870 this->Device->CoreDrawTriangles(cacheItem->PolyTri,
871 static_cast<unsigned char*
>(cacheItem->PolyColors->GetVoidPointer(0)), 4);
879 vtkUnsignedCharArray* Colors;
886 std::vector<float> CellPoints;
887 vtkNew<vtkUnsignedCharArray> CellColors;
890 PolyDataCache* cache;