1
$\begingroup$

Is there a way to view a vector field specified in voxels with a mask?

I have three 3D arrays with $x,y,z$ components of the fields at each voxel, as well as a 3D array of booleans saying which voxels should be viewed. All four arrays are the same size (roughly 60 x 60 x 60.)

So for a little test example:

testX = { (* X components *)
 {{-1, -1, -1}, {1, 1, 1}, {-1, -1, -1}},
 {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}},
 {{-1, -1, -1}, {1, 1, 1}, {1, 1, 1}}
};
testY = { (* Y components *)
 {{1, 1, 1}, {-1, -1, -1}, {-1, -1, -1}},
 {{-1, -1, -1}, {1, 1, 1}, {-1, -1, -1}},
 {{-1, -1, -1}, {-1, -1, -1}, {1, 1, 1}}
}; 
testZ = { (* Z components *)
 {{1, 1, 1}, {-1, -1, -1}, {1, 1, 1}},
 {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}},
 {{-1, -1, -1}, {-1, -1, -1}, {1, 1, 1}}
};
mask = {
 {{False, True, False}, {True, False, True}, {False, True, False}},
 {{False, True, False}, {True, False, True}, {False, True, False}},
 {{False, True, False}, {True, False, True}, {False, True, False}}
};

So in this test example the voxel at $(1,1,2)$ should show the vector $(-1,1,1)$, but voxel $(1,1,1)$ should not display.

$\endgroup$
  • $\begingroup$ How should a voxel "show" a vector? I am not sure that I can see what visualization method you had in mind. $\endgroup$ – MarcoB Feb 9 '17 at 17:06
  • $\begingroup$ @MarcoB just draw the vector in it (i.e. a 3d vector field). Like VectorPlot3D. But I want to mask some voxels. If necessary, I could assign $x,y,z$ values to each voxel (say voxel $(1,1,1)$ would be at $(1,1,1)$ in space) I guess. (But I figured there might be something like matlab's quiver which doesn't require $x,y$ values.) $\endgroup$ – user3658307 Feb 9 '17 at 17:22
  • $\begingroup$ So you imagine a three-dimensional grid of cubes and there is one arrow in each cube. But some of the arrows are not being displayed, as specified by mask? $\endgroup$ – C. E. Feb 9 '17 at 23:05
  • $\begingroup$ @C.E. Yes :) I'm hoping to be able to slice it, draw local streamlines in specific slices of the array, simulate a PDE in them, etc... later on. $\endgroup$ – user3658307 Feb 10 '17 at 0:51
1
$\begingroup$

I managed to do it crudely on my own (although I am certain it is suboptimal in many ways). In particular, it is not very visually pleasing and is slow for many vectors.

Here it is:

possibleElems = Array[{#1, #2, #3} &, {3, 3, 3}, {{1, 3}, {1, 3}, {1, 3}}];
hasMaskTrue = Select[ (mask[[  #[[1]], #[[2]], #[[3]]  ]]) &];
elemsToKeep = Flatten[hasMaskTrue /@ Flatten[possibleElems , 1], 1];
vecList = Map[
  {{#[[1]], #[[2]], #[[3]]},
    { testX[[#[[1]], #[[2]], #[[3]]]],
      testY[[#[[1]], #[[2]], #[[3]]]],
      testZ[[#[[1]], #[[2]], #[[3]]]]
     }
    } &, 
  possibleElems, {3}]
ListVectorPlot3D[ vecList, VectorPoints -> elemsToKeep ]

If anyone has a better solution, I encourage them to post it. :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.