Logo Search packages:      
Sourcecode: v-sim version File versions  Download package

int visuData_constrainedElementInTheBox ( VisuData data,
VisuElement *  element 
)

visuData_constrainedElementInTheBox: : a VisuData object ; : a VisuElement object.

Check all the nodes of the specified and change their coordinates if they are out of the bounding box. The position of each node is the result of the sum of their own position and of the box translation.

Returns: 1 if visuData_createAllNodes() should be called and the 'NodePositionChanged' should be emitted.

Definition at line 1569 of file visu_data.c.

References _VisuData::fromIntToVisuElement, _VisuData::fromVisuElementToInt, _VisuData::nodes, _VisuData::numberOfStoredNodes, _VisuData::privateDt, node_struct::translation, node_struct::x, node_struct::y, and node_struct::z.

{
  int *indexEle, i, j, k;
  gboolean moved, changed;
  float cartCoord[3], boxCoord[3];

  if (!data || !element)
    {
      fprintf(stderr, "WARNING! 'visuData_constrainedElementInTheBox' has been"
            " called with no 'data' or no 'element' attribute.\n");
      return 0;
    }
  indexEle = (int*)g_hash_table_lookup(data->fromVisuElementToInt, (gpointer)element);
  if (!indexEle)
    {
      fprintf(stderr, "WARNING! 'visuData_constrainedElementInTheBox' has been"
            " called with an 'element' attribute that is not in 'data' attribute.\n");
      return 0;
    }
  i = *indexEle;

  if (!data->fromIntToVisuElement[i]->rendered)
    return 0;

  DBG_fprintf(stderr, "Visu Data : Checking for nodes of element '%s' to be in the box.\n",
            element->name);
  changed = FALSE;
  for(j = 0; j < data->numberOfStoredNodes[i]; j++)
    {
      cartCoord[0] = data->nodes[i][j].x + data->privateDt->translation[0] +
      data->nodes[i][j].translation[0];
      cartCoord[1] = data->nodes[i][j].y + data->privateDt->translation[1] +
      data->nodes[i][j].translation[1];
      cartCoord[2] = data->nodes[i][j].z + data->privateDt->translation[2] +
      data->nodes[i][j].translation[2];
      visuDataConvert_XYZtoBoxCoordinates(data, boxCoord, cartCoord);
      moved = FALSE;
      for (k = 0; k < 3; k++)
      {
        while (boxCoord[k] < 0.)
          {
            moved = TRUE;
            boxCoord[k] += 1.;
          }
        while (boxCoord[k] > 1.)
          {
            moved = TRUE;
            boxCoord[k] -= 1.;
          }
      }
      if (moved)
      {
        changed = TRUE;
        visuDataConvert_boxCoordinatestoXYZ(data, cartCoord, boxCoord);
        data->nodes[i][j].translation[0] = cartCoord[0] - data->nodes[i][j].x -
          data->privateDt->translation[0];
        data->nodes[i][j].translation[1] = cartCoord[1] - data->nodes[i][j].y -
          data->privateDt->translation[1];
        data->nodes[i][j].translation[2] = cartCoord[2] - data->nodes[i][j].z -
          data->privateDt->translation[2];
      }
    }
  return changed;
}


Generated by  Doxygen 1.6.0   Back to index