<div dir="ltr"><div><div>Problem: for axis labels created using vtkCubeAxesActor, if we have more than 10 text labels, the labels and the data don't line-up, because the labels are positioned incorrectly on the axis.<br><br>What are we Getting in more Detail:<br>(a) If we have 9 data points (<10) we get 9 label points, with the last label at the end of the axis.  So the labels can be 1,2,3,4,5,6,7,8,9, which lines-up nicely with the data: all is good in the world.<br>(b) If we have 10 data points, we get get 6 labels points with the last label one at the end of the axis.  We compute a label skip factor of 2.  We start at the beginning of the axis.  We label 1,3,5,7,9,11 <- what category is this last label?? We only have 10 data points!  So the last data label does not line-up with its data. <br>(c) If we have 11 data points, we again get 6 label points with the last label positioned a short distance back from the end of the axis.  Again we compute a label skip factor of 2.  We begin to label at the beginning of the axis.  So we get 1,3,5,7,9,11.  Ok, because we had 11 data-points, but now we land-up with the label for the last data element being back from the end of the axis i.e. the data label does not line-up with its data. <br><br>What we want:<br>(a) VTK seems to make a quite reasonable assumption to limit the number of labels to less than 10, so lets stick with that.<br>(b) VTK works fine with data sets with 9 or fewer elements, so lets focus on data-sets with 10 or more data-points.<br>(c) We need to handle data-sets with an even count of elements slightly differently from data-sets with an odd count of elements.  (For a more generic handling this would be if the count of the elements is divisible by the skip factor, but for the moment lets stick to a skip factor of 2 and thus even or odd element counts).<br>(d) For a data-set with an odd count of elements (lets say 11) we can easily imagine the handling to be:<br>Smallest at the start (e.g. 1)<br>Biggest at the end (eg. 11)<br>Then fill-in the labels using the skip factor (2 in this case), so we get something like 1,3,5,7,9,11<br>(e) For a data-set with an even count of elements (lets say 10), we need to have a gap between the last label and the end of the axis.  The end of the axis seems most logical place for this gap, so the last label point is back a bit from the end of the axis.  So:<br>Smallest at the start (e.g. 1)<br>Then fill in the labels using the skip factor, so something like 1,3,5,7,9<br>and we happily land-up with a label of 9 being a bit back from the end of the axis.<br><br>So what was the difference between what we want and what we are getting?<br>The problem is not about the calculation of the number of labels - that is fine.<br>The problem is the positioning of the labels on the axis - is the last label at the end of the axis or bit back from the end?<br>Today, for data-sets with an even number of elements, we are getting the last label at the end of the axis.  This is incorrect because for an even number of elements, we want the last label to be positioned back from the end of axis.<br>Today, for data-sets with odd number of elements, we are getting the last label positioned with a gap before the end of the axis.  Again this is incorrect, because the label should be positioned at the end of the axis.<br><br>Questions:<br>I'm using an old'ish version of VTK 6.1 - has this issue been fixed in a newer version?<br>Am I misunderstanding something or can I raise a defect for this?<br><br>Some Code:<br><br>vtkSmartPointer<vtkCubeAxesActor> cubeAxesActor = vtkSmartPointer<vtkCubeAxesActor>::New();<br>cubeAxesActor->SetBounds(outputPolyData->GetBounds());<br>cubeAxesActor->SetCamera(Renderer->GetActiveCamera());<br>cubeAxesActor->GetTitleTextProperty(0)->SetColor(1.0, 1.0, 1.0);    //White<br>cubeAxesActor->GetLabelTextProperty(0)->SetColor(1.0, 1.0, 1.0);    //White<br>cubeAxesActor->SetXTitle("X-Axis");<br>cubeAxesActor->GetXAxesGridlinesProperty()->SetColor(1.0, 1.0, 1.0);    //White<br><br>cubeAxesActor->DrawXGridlinesOn();<br>cubeAxesActor->SetGridLineLocation(VTK_GRID_LINES_FURTHEST);<br>cubeAxesActor->SetFlyModeToOuterEdges();        //Place the axes on the outer edges of the cube<br><br>//Set the labels on the x-axis<br>vtkSmartPointer<vtkStringArray> XAxisLabels = vtkSmartPointer<vtkStringArray>::New();<br>std::vector<std::string> Labels = ResultsServer->GetXLabels();    //Get a list of axis labels<br>if (!Labels.empty()) {<br><br>    int32_t SkipFactor = (Labels.size() / 10) + 1;<br>    int32_t Counter = 0;<br><br>    //Evenly divisble<br>    for (auto LabelsIt = std::begin(Labels); LabelsIt != std::end(Labels); ++LabelsIt)<br>        if (Counter++ % SkipFactor == 0)<br>            XAxisLabels->InsertNextValue(LabelsIt->c_str());<br><br>    cubeAxesActor->SetXAxisRange(0.0, Labels.size() * 1.0);<br>    cubeAxesActor->GetLabelTextProperty(0)->SetFontSize(20);<br>    cubeAxesActor->GetLabelTextProperty(0)->SetOrientation(90.0);<br>    cubeAxesActor->SetAxisLabels(0, XAxisLabels);<br><br>    Labels.clear();<br>}<br><br></div>Kind regards,<br></div>Michael<br></div>