Exemplo n.º 1
0
 /**
  * Refreshes the derivatives if they have not been refreshed in the refreshSteps() method (ie if
  * the variable "refreshDerivsLater" is false).
  */
 protected void refreshDerivsIfNeeded() {
   if (!refreshDerivsLater) return;
   refreshDerivsLater = false;
   for (ParticleModel part : getModels()) {
     part.updateDerivatives();
     part.firePropertyChange("steps", null, null); // $NON-NLS-1$
   }
 }
Exemplo n.º 2
0
 /** Trims all steps after endFrame. */
 protected void trimSteps() {
   // return if trimming not needed
   VideoClip clip = trackerPanel.getPlayer().getVideoClip();
   int n = clip.getFrameCount() - 1;
   int end = getEndFrame() == Integer.MAX_VALUE ? n : getEndFrame();
   while (end > getStartFrame() && !clip.includesFrame(end)) {
     end--;
   }
   if (end >= lastValidFrame) return;
   int trimCount = (tracePtsPerStep * (lastValidFrame - end)) / clip.getStepSize();
   ParticleModel[] models = getModels();
   for (ParticleModel next : models) {
     // create smaller trace arrays and copy existing points into them
     next.locked = false;
     int traceLength = next.traceX.length - trimCount;
     if (traceLength < 0) return; // trap for error during closing
     next.prevX = next.traceX;
     next.prevY = next.traceY;
     next.traceX = new double[traceLength];
     next.traceY = new double[traceLength];
     System.arraycopy(next.prevX, 0, next.traceX, 0, traceLength);
     System.arraycopy(next.prevY, 0, next.traceY, 0, traceLength);
     // reduce number of steps
     next.steps.setLength(end + 1);
     // refresh derivatives
     next.updateDerivatives(end - 2, lastValidFrame - end + 2);
     // restore state
     restoreState(end);
     next.support.firePropertyChange("steps", null, null); // $NON-NLS-1$
     next.locked = true;
   }
   lastValidFrame = end;
   repaint();
   //		trackerPanel.repaint();
 }
Exemplo n.º 3
0
 /**
  * Saves an object's data to an XMLControl.
  *
  * @param control the control to save to
  * @param obj the object to save
  */
 public void saveObject(XMLControl control, Object obj) {
   ParticleModel p = (ParticleModel) obj;
   // save mass
   control.setValue("mass", p.getMass()); // $NON-NLS-1$
   // save track data
   XML.getLoader(TTrack.class).saveObject(control, obj);
   // save parameters, initial values and functions
   Parameter[] params = p.getParamEditor().getParameters();
   control.setValue("user_parameters", params); // $NON-NLS-1$
   Parameter[] inits = p.getInitEditor().getParameters();
   control.setValue("initial_values", inits); // $NON-NLS-1$
   UserFunction[] functions = p.getFunctionEditor().getMainFunctions();
   control.setValue("main_functions", functions); // $NON-NLS-1$
   functions = p.getFunctionEditor().getSupportFunctions();
   if (functions.length > 0) control.setValue("support_functions", functions); // $NON-NLS-1$
   // save start and end frames (if custom)
   if (p.startFrame > 0) control.setValue("start_frame", p.startFrame); // $NON-NLS-1$
   if (p.endFrame < Integer.MAX_VALUE) control.setValue("end_frame", p.endFrame); // $NON-NLS-1$
   // save inspector size and position
   if (p.inspector != null && p.trackerPanel != null && p.trackerPanel.getTFrame() != null) {
     // save inspector location relative to frame
     TFrame frame = p.trackerPanel.getTFrame();
     int x = p.inspector.getLocation().x - frame.getLocation().x;
     int y = p.inspector.getLocation().y - frame.getLocation().y;
     control.setValue("inspector_x", x); // $NON-NLS-1$
     control.setValue("inspector_y", y); // $NON-NLS-1$  		
     control.setValue("inspector_h", p.inspector.getHeight()); // $NON-NLS-1$
     control.setValue("inspector_visible", p.inspector.isVisible()); // $NON-NLS-1$
   }
 }
Exemplo n.º 4
0
 protected boolean isModelsVisible() {
   for (ParticleModel model : getModels()) {
     if (model.isTraceVisible()
         || (model.isVisible()
             && (model.isPositionVisible(trackerPanel)
                 || model.isVVisible(trackerPanel)
                 || model.isAVisible(trackerPanel)))) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 5
0
 /** Refreshes step positions. */
 protected void refreshSteps() {
   locked = true;
   if (refreshStepsLater) return;
   // return if this is an empty dynamic system
   if (this instanceof DynamicSystem) {
     DynamicSystem system = (DynamicSystem) this;
     if (system.particles.length == 0) return;
   }
   if (trackerPanel != null) {
     refreshDerivsLater = trackerPanel.getPlayer().getClipControl().isPlaying();
     int n = trackerPanel.getFrameNumber();
     VideoClip clip = trackerPanel.getPlayer().getVideoClip();
     // determine last frame to be marked (must satisfy both model and clip)
     int end = Math.min(getEndFrame(), n);
     while (end > getStartFrame() && !clip.includesFrame(end)) {
       end--;
     }
     if (end <= lastValidFrame) return;
     if (lastValidFrame == -1) {
       reset(); // initializes model, sets lastValidFrame to marked frame, if any
       if (lastValidFrame == -1 || end <= lastValidFrame) return;
     }
     int start = lastValidFrame;
     Tracker.logTime(
         this.getClass().getSimpleName()
             + this.hashCode()
             + " refreshing steps "
             + start
             + " to "
             + end); //$NON-NLS-1$ //$NON-NLS-2$
     boolean singleStep = (end - start == 1);
     // step forward to end
     ImageCoordSystem coords = trackerPanel.getCoords();
     // get underlying coords if appropriate
     boolean useDefault = isUseDefaultReferenceFrame();
     while (useDefault && coords instanceof ReferenceFrame) {
       coords = ((ReferenceFrame) coords).getCoords();
     }
     double startTime = t0 + dt * tracePtsPerStep * (start - getStartFrame()) / clip.getStepSize();
     double stepSize = 1.0 * clip.getStepSize() / tracePtsPerStep;
     int stepCount = (tracePtsPerStep * (end - start)) / clip.getStepSize();
     ParticleModel[] models = getModels();
     // prepare larger trace arrays and copy existing points into them
     for (ParticleModel next : models) {
       next.locked = false;
       int traceLength = next.traceX.length + stepCount;
       next.prevX = next.traceX;
       next.prevY = next.traceY;
       next.traceX = new double[traceLength];
       next.traceY = new double[traceLength];
       System.arraycopy(next.prevX, 0, next.traceX, 0, next.prevX.length);
       System.arraycopy(next.prevY, 0, next.traceY, 0, next.prevY.length);
     }
     for (int i = 0; i < stepCount; i++) {
       int stepNumber = i + 1;
       int frameNumber = start + (int) (stepNumber * stepSize);
       time = startTime + stepNumber * dt;
       Point2D[] points = getNextTracePositions();
       if (points == null) continue;
       AffineTransform transform = coords.getToImageTransform(frameNumber);
       for (int j = 0; j < models.length; j++) {
         transform.transform(points[j], points[j]);
         // determine if point is invalid due to out of bounds
         boolean valid =
             Math.abs(points[j].getX()) < xLimit && Math.abs(points[j].getY()) < yLimit;
         if (!valid && !invalidWarningShown) {
           invalidWarningShown = true;
           Runnable runner = new Runnable() { // avoids deadlock?
                 public void run() {
                   //            		if (invalidWarningShown) return;
                   JOptionPane.showMessageDialog(
                       trackerPanel,
                       TrackerRes.getString("ParticleModel.Dialog.Offscreen.Message1")
                           + XML.NEW_LINE //$NON-NLS-1$
                           + TrackerRes.getString(
                               "ParticleModel.Dialog.Offscreen.Message2"), //$NON-NLS-1$
                       TrackerRes.getString("ParticleModel.Dialog.Offscreen.Title"), // $NON-NLS-1$
                       JOptionPane.WARNING_MESSAGE);
                 }
               };
           SwingUtilities.invokeLater(runner);
         }
         models[j].traceX[models[j].prevX.length + i] = valid ? points[j].getX() : Double.NaN;
         models[j].traceY[models[j].prevY.length + i] = valid ? points[j].getY() : Double.NaN;
         if (stepNumber % tracePtsPerStep == 0) { // refresh position step
           saveState(frameNumber);
           PositionStep step = (PositionStep) models[j].getStep(frameNumber);
           if (step == null) {
             step = createPositionStep(models[j], frameNumber, 0, 0);
             step.setFootprint(models[j].getFootprint());
             models[j].steps.setStep(frameNumber, step);
           }
           step.getPosition().setPosition(valid ? points[j] : nan); // this method is fast
         }
       }
     }
     int count = 4 + (end - start);
     int startUpdate = start;
     // step back twice to pick up possible valid derivatives
     if (startUpdate > clip.getStepSize()) startUpdate -= clip.getStepSize();
     if (startUpdate > clip.getStepSize()) startUpdate -= clip.getStepSize();
     lastValidFrame = end;
     for (ParticleModel next : models) {
       next.steps.setLength(end + 1);
       coords = trackerPanel.getCoords(); // get active coords
       // special treatment if this is the origin of current reference frame
       if (coords instanceof ReferenceFrame
           && ((ReferenceFrame) coords).getOriginTrack() == next) {
         // set origins of reference frame
         boolean prev = next.refreshing; // save refreshing value
         next.refreshing = true;
         ((ReferenceFrame) coords).setOrigins();
         // then set positions to zero wrt origins
         for (int i = 0; i < clip.getStepCount(); i++) {
           int frameNumber = clip.stepToFrame(i);
           PositionStep step = (PositionStep) next.getStep(frameNumber);
           if (step == null) continue;
           AffineTransform transform = coords.getToImageTransform(frameNumber);
           next.point.setLocation(0, 0);
           transform.transform(next.point, next.point);
           step.getPosition().setPosition(next.point); // this method is fast
         }
         next.refreshing = prev; // restore refreshing value
         if (!refreshDerivsLater) {
           next.updateDerivatives(startUpdate, count);
         }
       } else if (!refreshDerivsLater) {
         next.updateDerivatives(startUpdate, count);
       }
       if (next.vAtOrigin) next.vTailsToOriginItem.doClick();
       if (next.aAtOrigin) next.aTailsToOriginItem.doClick();
       if (!refreshDerivsLater) {
         if (singleStep)
           next.support.firePropertyChange("step", null, new Integer(n)); // $NON-NLS-1$
         else next.support.firePropertyChange("steps", null, null); // $NON-NLS-1$
       }
       // erase refreshed steps
       for (int i = start + 1; i <= end; i++) {
         Step step = next.getStep(i);
         if (step != null) step.erase();
       }
       next.locked = true;
     }
     trackerPanel.repaint();
   }
 }
Exemplo n.º 6
0
 /**
  * Loads an object with data from an XMLControl.
  *
  * @param control the control
  * @param obj the object
  * @return the loaded object
  */
 public Object loadObject(XMLControl control, Object obj) {
   // load track data
   XML.getLoader(TTrack.class).loadObject(control, obj);
   ParticleModel p = (ParticleModel) obj;
   p.mass = control.getDouble("mass"); // $NON-NLS-1$
   p.inspectorX = control.getInt("inspector_x"); // $NON-NLS-1$
   p.inspectorY = control.getInt("inspector_y"); // $NON-NLS-1$
   p.inspectorH = control.getInt("inspector_h"); // $NON-NLS-1$
   p.showInspector = control.getBoolean("inspector_visible"); // $NON-NLS-1$
   Parameter[] params = (Parameter[]) control.getObject("user_parameters"); // $NON-NLS-1$
   p.getParamEditor().setParameters(params);
   params = (Parameter[]) control.getObject("initial_values"); // $NON-NLS-1$
   // remove trailing "0" from initial condition parameters
   for (int i = 0; i < params.length; i++) {
     Parameter param = params[i];
     String name = param.getName();
     int n = name.lastIndexOf("0"); // $NON-NLS-1$
     if (n > -1) {
       // replace parameter with new one
       name = name.substring(0, n);
       Parameter newParam = new Parameter(name, param.getExpression());
       newParam.setDescription(param.getDescription());
       newParam.setNameEditable(false);
       params[i] = newParam;
     }
   }
   p.getInitEditor().setParameters(params);
   UserFunction[] functions =
       (UserFunction[]) control.getObject("main_functions"); // $NON-NLS-1$
   p.getFunctionEditor().setMainFunctions(functions);
   functions = (UserFunction[]) control.getObject("support_functions"); // $NON-NLS-1$
   if (functions != null) {
     for (int i = 0; i < functions.length; i++) {
       p.getFunctionEditor().addObject(functions[i], false);
     }
   }
   p.functionPanel.refreshFunctions();
   int n = control.getInt("start_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.startFrame = n;
   else {
     p.startFrameUndefined = true;
   }
   n = control.getInt("end_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.endFrame = n;
   return obj;
 }