547 this->cache =
new PolyDataCache();
558 this->Points = points;
559 this->Colors = colors;
560 this->CellColors->SetNumberOfComponents(colors->GetNumberOfComponents());
565 this->DrawLines(polyData, scalarMode, x, y, scale);
569 this->DrawPolygons(polyData, scalarMode, x, y, scale);
580 struct PolyDataCacheItem
584 std::vector<float> PolyTri;
588 std::vector<float> Lines;
597 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator itPrev = this->PrevFrameCache.begin();
598 for (; itPrev != this->PrevFrameCache.end(); ++itPrev)
600 delete itPrev->second;
603 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator it = this->CurrentFrameCache.begin();
604 for (; it != this->CurrentFrameCache.end(); ++it)
610 PolyDataCacheItem* GetCacheEntry(vtkPolyData* key)
612 PolyDataCacheItem* cacheItem = this->CurrentFrameCache[
key];
613 if (cacheItem ==
nullptr)
615 cacheItem = this->PrevFrameCache[
key];
616 if (cacheItem ==
nullptr)
618 cacheItem =
new PolyDataCacheItem();
625 this->PrevFrameCache.erase(key);
629 this->CurrentFrameCache[
key] = cacheItem;
640 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator itPrev = this->PrevFrameCache.begin();
641 for (; itPrev != this->PrevFrameCache.end(); ++itPrev)
643 delete itPrev->second;
647 this->PrevFrameCache.clear();
650 std::swap(this->PrevFrameCache, this->CurrentFrameCache);
655 std::map<vtkPolyData*, PolyDataCacheItem*> PrevFrameCache;
656 std::map<vtkPolyData*, PolyDataCacheItem*> CurrentFrameCache;
663 float const posX,
float const posY,
float const scale,
vtkIdType cellId,
int scalarMode)
665 this->CellPoints.reserve(this->NumPointsCell * 2);
666 this->CellColors->SetNumberOfTuples(this->NumPointsCell);
667 for (
int i = 0; i < this->NumPointsCell; i++)
670 this->Points->GetPoint(this->PointIds[i], point);
673 float const x =
static_cast<float>(
point[0]) + posX;
674 float const y =
static_cast<float>(
point[1]) + posY;
675 this->CellPoints.push_back(x * scale);
676 this->CellPoints.push_back(y * scale);
683 mappedColorId = this->PointIds[i];
686 mappedColorId = cellId;
689 std::cerr <<
"Scalar mode not supported!" << std::endl;
693 this->CellColors->SetTuple(i, mappedColorId, this->Colors);
703 vtkPolyData* polyData,
int scalarMode,
float const x,
float const y,
float const scale)
705 PolyDataCacheItem* cacheItem = this->cache->GetCacheEntry(polyData);
707 if (polyData->
GetMTime() > cacheItem->LinesLoadingTime)
709 vtkNew<vtkGenericCell> genericCell;
710 cacheItem->Lines.clear();
711 cacheItem->LineColors->Reset();
715 cacheItem->Lines.reserve(numVertices * 2);
716 cacheItem->LineColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
717 cacheItem->LineColors->SetNumberOfTuples(numVertices);
721 vtkCellIterator* cellIter =
nullptr;
729 vtkIdType actualNumPointsCell = genericCell->GetNumberOfPoints();
731 for (
int i = 0; i < actualNumPointsCell - 1; ++i)
733 this->NumPointsCell = 2;
734 this->PointIds = genericCell->GetPointIds()->
GetPointer(i);
736 this->MapCurrentCell(x, y, scale, cellId, scalarMode);
739 for (
int j = 0; j < this->NumPointsCell; j++)
741 cacheItem->Lines.push_back(this->CellPoints[2 * j]);
742 cacheItem->Lines.push_back(this->CellPoints[2 * j + 1]);
744 double* color4 = this->CellColors->GetTuple(j);
745 cacheItem->LineColors->InsertTuple4(
746 vertOffset + j, color4[0], color4[1], color4[2], color4[3]);
749 vertOffset += this->NumPointsCell;
750 this->CellColors->Reset();
751 this->CellPoints.clear();
756 cacheItem->LinesLoadingTime.Modified();
760 if (!cacheItem->Lines.empty())
762 this->Device->DrawLines(cacheItem->Lines.data(),
763 static_cast<int>(cacheItem->Lines.size() / 2), cacheItem->LineColors->GetPointer(0),
764 cacheItem->LineColors->GetNumberOfComponents());
772 vtkIdType GetCountTriangleVertices(vtkPolyData* polyData)
775 vtkNew<vtkGenericCell> genericCell;
776 vtkCellIterator* cellIter =
nullptr;
782 this->NumPointsCell = genericCell->GetNumberOfPoints();
783 this->PointIds = genericCell->GetPointIds()->
GetPointer(0);
784 numTriVert += 3 * (this->NumPointsCell - 2);
797 vtkPolyData* polyData,
int scalarMode,
float const x,
float const y,
float const scale)
799 PolyDataCacheItem* cacheItem = this->cache->GetCacheEntry(polyData);
801 if (polyData->
GetMTime() > cacheItem->PolygonsLoadingTime)
803 cacheItem->PolyTri.clear();
804 cacheItem->PolyColors->Reset();
807 vtkIdType const totalTriVert = this->GetCountTriangleVertices(polyData);
808 cacheItem->PolyTri.reserve(totalTriVert * 2);
809 cacheItem->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
810 cacheItem->PolyColors->SetNumberOfTuples(totalTriVert);
815 cacheItem->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
817 vtkNew<vtkGenericCell> genericCell;
818 vtkCellIterator* cellIter =
nullptr;
827 this->NumPointsCell = genericCell->GetNumberOfPoints();
828 this->PointIds = genericCell->GetPointIds()->
GetPointer(0);
830 this->MapCurrentCell(x, y, scale, cellId, scalarMode);
833 for (
int i = 0; i < this->NumPointsCell - 2; i++)
835 cacheItem->PolyTri.push_back(this->CellPoints[0]);
836 cacheItem->PolyTri.push_back(this->CellPoints[1]);
837 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 2]);
838 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 3]);
839 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 4]);
840 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 5]);
843 vtkIdType const triangOffset = vertOffset + 3 * i;
844 double* color4 = this->CellColors->GetTuple(0);
845 cacheItem->PolyColors->InsertTuple4(
846 triangOffset, color4[0], color4[1], color4[2], color4[3]);
848 color4 = this->CellColors->GetTuple(i + 1);
849 cacheItem->PolyColors->InsertTuple4(
850 triangOffset + 1, color4[0], color4[1], color4[2], color4[3]);
852 color4 = this->CellColors->GetTuple(i + 2);
853 cacheItem->PolyColors->InsertTuple4(
854 triangOffset + 2, color4[0], color4[1], color4[2], color4[3]);
857 vertOffset += 3 * (this->NumPointsCell - 2);
858 this->CellColors->Reset();
859 this->CellPoints.clear();
863 cacheItem->PolygonsLoadingTime.Modified();
867 if (!cacheItem->PolyTri.empty())
869 this->Device->CoreDrawTriangles(cacheItem->PolyTri, cacheItem->PolyColors->GetPointer(0), 4);
877 vtkUnsignedCharArray* Colors;
884 std::vector<float> CellPoints;
885 vtkNew<vtkUnsignedCharArray> CellColors;
888 PolyDataCache* cache;