Beispiel #1
0
  /**
   * This method exists for the following reason:
   *
   * <p>The segmenter receives at each frame a cropped image to operate on, depending on the user
   * specifying a ROI. It therefore returns spots whose coordinates are with respect to the top-left
   * corner of the ROI, not of the original image.
   *
   * <p>This method modifies the given spots to put them back in the image coordinate system.
   * Additionally, is a non-square ROI was specified (e.g. a polygon), it prunes the spots that are
   * not within the polygon of the ROI.
   *
   * @param spotsThisFrame the spot list to inspect
   * @param settings the {@link Settings} object that will be used to retrieve the image ROI and
   *     cropping information
   * @return a list of spot. Depending on the presence of a polygon ROI, it might be a new, pruned
   *     list. Or not.
   */
  protected List<Spot> translateAndPruneSpots(
      final List<Spot> spotsThisFrame, final Settings settings) {
    // Get Roi
    final Polygon polygon;
    if (null == settings.imp || null == settings.imp.getRoi()) {
      polygon = null;
    } else {
      polygon = settings.imp.getRoi().getPolygon();
    }

    // Put them back in the right referential
    final float[] calibration = settings.getCalibration();
    TMUtils.translateSpots(
        spotsThisFrame,
        settings.xstart * calibration[0],
        settings.ystart * calibration[1],
        settings.zstart * calibration[2]);
    List<Spot> prunedSpots;
    // Prune if outside of ROI
    if (null != polygon) {
      prunedSpots = new ArrayList<Spot>();
      for (Spot spot : spotsThisFrame) {
        if (polygon.contains(
            spot.getFeature(Spot.POSITION_X) / calibration[0],
            spot.getFeature(Spot.POSITION_Y) / calibration[1])) prunedSpots.add(spot);
      }
    } else {
      prunedSpots = spotsThisFrame;
    }
    return prunedSpots;
  }
Beispiel #2
0
  public static void main(String[] argv) {
    Spot outter = new Spot();
    outter.setRadius(3.0);
    Spot inner = new Spot(0, 0, 2.0);

    double intersection = outter.getArea() - inner.getArea();
    System.out.println(intersection);
  }
    // draw all objects in the game
    private void doDraw(Canvas canvas) {
      // draw the background

      canvas.drawColor(Color.WHITE);

      spot.doDraw(canvas);
      spot2.doDraw(canvas);
      spot3.doDraw(canvas);
      ball.doDraw(canvas);
    }
Beispiel #4
0
 @Override
 public void startElement(String uri, String localName, String qName, Attributes atts)
     throws SAXException {
   if ("position".equals(qName)) {
     Spot S = new Spot();
     S._pos = atts.getValue("name");
     String temp = atts.getValue("playing-time");
     if (temp != null) {
       S._playingtime = Double.parseDouble(temp);
     }
     _spots.add(S);
   } else if ("team-weight".equals(qName)) {
     _teamweight = Double.parseDouble(atts.getValue("value"));
   }
 }
Beispiel #5
0
  // TODO: Remove these?
  // WORKS FOR NOW THOUGH =)
  @Override
  protected void onResume() {
    super.onResume();

    // Set spot images
    imagesArray = new ArrayList<HashMap<String, String>>();
    Spot.getPhotosBySpotID(gridview, dataAdapter, imagesArray, context, spot_id);
  }
Beispiel #6
0
 // TODO Possibly delete this
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   // TODO: uncomment and figure out how to refresh from coming back here
   // if (requestCode == 0) {
   //    if (resultCode == Activity.RESULT_OK) {
   // Refresh list because photo was added
   imagesArray = new ArrayList<HashMap<String, String>>();
   Spot.getPhotosBySpotID(gridview, dataAdapter, imagesArray, context, spot_id);
   //    }
   // }
 }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    SpotHolder holder;

    if (row == null) {
      LayoutInflater inflater = ((Activity) context).getLayoutInflater();
      row = inflater.inflate(layoutResourceId, parent, false);
      holder = new SpotHolder();
      holder.name = (TextView) row.findViewById(R.id.spotName);
      holder.distance = (TextView) row.findViewById(R.id.distance);
      holder.street = (TextView) row.findViewById(R.id.street);
      holder.city = (TextView) row.findViewById(R.id.city);

      row.setTag(holder);
    } else holder = (SpotHolder) row.getTag();

    Spot spot = data.get(position);

    holder.name.setText(spot.getName());
    holder.distance.setText(Float.toString(spot.getDistance()));
    holder.street.setText(spot.getStreet());
    holder.city.setText(spot.getPostcode() + " " + spot.getCity());
    return row;
  }
 // move all objects in the game
 private void doUpdate(double elapsed) {
   ball.doUpdate(elapsed, ballX, ballY);
   spot.doUpdate(elapsed, spotX, spotY);
   spot2.doUpdate(elapsed, spotX2, spotY2);
   spot3.doUpdate(elapsed, spotX3, spotY3);
 }
    // the main loop
    @Override
    public void run() {
      player = MediaPlayer.create(context, R.raw.alarmnoise);
      player.start();
      lastTime = System.currentTimeMillis();

      while (isRunning) {

        // grab hold of the canvas
        Canvas canvas = surfaceHolder.lockCanvas();
        if (canvas == null) {
          // trouble -- exit nicely
          isRunning = false;
          continue;
        }

        synchronized (surfaceHolder) {

          // compute how much time since last time around
          long now = System.currentTimeMillis();
          double elapsed = (now - lastTime) / 1000.0;
          lastTime = now;

          float screenX = size.x;
          float screenY = size.y;

          // top
          if (ballY <= (screenX + 40) - screenX) {
            ballY = 45;
          } else {
            ballY += RollerBallActivity.accelY * 3;
          }
          // left side
          if (ballX <= (screenY + 40) - screenY) {
            ballX = 45;
          } else {
            ballX += RollerBallActivity.accelX * 3;
          }
          // bottom
          if (ballY > size.y - 40) {
            ballY = size.y - 45;
          } else {
            ballY += RollerBallActivity.accelY * 3;
          }
          // right side
          if (ballX > size.x - 40) {
            ballX = size.x - 45;
          } else {
            ballX += RollerBallActivity.accelX * 3;
          }

          if ((Math.abs(ball.x - spotX) < 20 && Math.abs(ball.y - spotY) < 50) && hasSpot1 == 0) {
            spot.changeImage(context);
            greenSquareAmount++;
            hasSpot1 = 1;
          }
          if ((Math.abs(ball.x - spotX2) < 20 && Math.abs(ball.y - spotY2) < 50) && hasSpot2 == 0) {
            spot2.changeImage(context);
            greenSquareAmount++;
            hasSpot2 = 1;
          }
          if ((Math.abs(ball.x - spotX3) < 20 && Math.abs(ball.y - spotY3) < 50) && hasSpot3 == 0) {
            spot3.changeImage(context);
            greenSquareAmount++;
            hasSpot3 = 1;
          }

          if (greenSquareAmount > 2) {
            player.stop();
            ((Activity) context).finish();
            System.out.println("complete");
          }
          // update/draw
          doUpdate(elapsed);
          doDraw(canvas);
        }

        // release the canvas
        if (canvas != null) {
          surfaceHolder.unlockCanvasAndPost(canvas);
        }
      }
    }