2020-12-26 01:56 阅读 1

Inconsistent pixel location from imagedata vs polydata

Hi! I was playing around with vtk.js and bumped upon a problem, I have tried to create a toy example where the problem becomes clear. I generated a checkerboard in imageData and want to draw a contour around a pixel using polyData. The imageData is initialized with the default coordinate system etc so the mapping between the voxel and world coordinates should be one-on-one. A square (polyData) with edge length 1 is generated starting from the pixel. You can find the code here.

However, the results that I'm seeing are not in line with what I would expect: The lines around the pixel do not correspond with the pixels. image

This issue persists across grid sizes and dimensions. In general it seems like n-1 polyData squares fit in n pixels.

I could work around it for this specific example but the issue seems more fundamental as the one-on-one mapping is not correct. Is this intended behavior? If so what is the proper way to get my desired behavior?

Thanks in advance!


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • weixin_39590566 weixin_39590566 2020-12-26 01:56

    What you see is what you are suppose to get. If you wanted the 2 to be aligned, you will create a grid of dimensions 11x11x1 and put your scalars on the cells or adjust your spacing.

    Right now, you are telling the grid to have 10 points along (x, y) which mean the minimum coordinate is (0, 0) and the max coordinate is (9, 9). And that is exactly what we see here.

    点赞 评论 复制链接分享
  • weixin_39868034 weixin_39868034 2020-12-26 01:56

    Thanks for the answer I understand what you are saying. However, this makes the use of the indexToWorld function on imageData a bit strange no?

    The imageData grid has 10x10x1 voxels and it has a function indexToWorld. It makes sense to me that if I were to ask the world location of a voxel and I draw this location that this world coordinate is either consistently centered inside of this voxel or in a consistent corner (e.g. bottom left) of this voxel. But this is not the case. To clarify, in the following image, I have drawn a little square in each world coordinate belonging to the voxel.


    What would the best way be to for example always draw in the bottom left corner of the pixel? Is there another function than indexToWorld?

    Thank you so much!

    点赞 评论 复制链接分享
  • weixin_39590566 weixin_39590566 2020-12-26 01:56

    I think the index to world is for points not for cells/voxels. It is true for images and vtkImageMapper it is a little bit different but technically if you want the center of a cell, you could do the mean of all its points or just 2 of them in that case where you get those coordinates from (i,j) and (i+1, j+1). But that assume you actually defined your mesh accordingly with 11 points and your data on cells.

    Here the image mapper is basically showing the data as a texture on top of your geometry which does not make it aligned with the mesh/voxels.

    点赞 评论 复制链接分享
  • weixin_39868034 weixin_39868034 2020-12-26 01:56

    Thanks for the clarifications! 👍

    点赞 评论 复制链接分享