@Test
  public void testExtractFeaturesExtractsFeaturesCorrectly() {
    Word w = new Word(0, 1, "test");
    regions.add(w);

    WavReader reader = new WavReader();
    WavData wav = null;
    try {
      wav = reader.read(TEST_DIR + "/bdc-test.wav");
    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (AuToBIException e) {
      e.printStackTrace();
    }
    w.setAttribute("wav", wav);

    try {
      fe.extractFeatures(regions);
      Spectrum s = (Spectrum) w.getAttribute("spectrum");
      assertEquals(835, s.numFrames());
      assertEquals(256, s.numFreqs());
      // Assume that the spectrum extraction algorithm is tested in SpectrumExtractor.
      // Here we'll make sure that the generated spectrum passes some sanity checks.
    } catch (FeatureExtractorException e) {
      fail();
    }
  }
示例#2
0
  @Override
  public Spectrum shade(HitRecord hit, Light light) {
    Spectrum spectrum = new Spectrum(0.f, 0.f, 0.f);
    Vector3f hitPoint = hit.getIntersectionPoint();
    Vector3f normal = hit.getNormal();
    normal.normalize();
    Spectrum cl = light.getCl(hitPoint);
    Vector3f L = light.getL(hitPoint);

    Vector3f rayDir = hit.getRayDir();
    rayDir.normalize();

    // Diffuse reflectance term
    float nDotL = normal.dot(L);
    if (nDotL >= 0) {
      spectrum.append(cl.multipliedBy(diffuse).multipliedBy(nDotL));

      // Specular reflectance term
      Vector3f h = new Vector3f(L);
      h.sub(rayDir);
      h.normalize();
      float hDotN = (float) Math.pow(h.dot(normal), shininess);
      spectrum.append(specular.multipliedBy(cl).multipliedBy(hDotN));
    }
    // Ambient reflectance term
    cl = light.getCl(hitPoint);
    Spectrum amb = ambient.multipliedBy(cl);
    spectrum.append(amb);

    spectrum.clampMax(1.f);
    spectrum.clampMin(0.f);

    return spectrum;
  }
示例#3
0
  public void set(Point2f pixel, Spectrum spectrum) {
    // update maximum
    if (!Helper.CLAMPING) {
      if (spectrum.r > max.r) max.r = spectrum.r;
      if (spectrum.g > max.g) max.g = spectrum.g;
      if (spectrum.b > max.b) max.b = spectrum.b;
    }
    // no values smaller than 0
    if (spectrum.r < 0) spectrum.r = 0;
    if (spectrum.g < 0) spectrum.g = 0;
    if (spectrum.b < 0) spectrum.b = 0;
    if (Helper.CLAMPING) {
      if (spectrum.r > 1) spectrum.r = 1;
      if (spectrum.g > 1) spectrum.g = 1;
      if (spectrum.b > 1) spectrum.b = 1;
    }
    this.image[(int) pixel.getX() - 1][(int) pixel.getY() - 1] = spectrum;

    if (Helper.SHOW_PROGRESS) {
      int i = (int) pixel.getX() - 1;
      int j = (int) pixel.getY() - 1;
      if (Helper.CLAMPING)
        this.img.setRGB(
            i,
            height - 1 - j,
            ((int) (255.f * this.image[i][j].r) << 16)
                | ((int) (255.f * this.image[i][j].g) << 8)
                | ((int) (255.f * this.image[i][j].b)));
      else
        this.img.setRGB(
            i,
            height - 1 - j,
            ((int) (255.f * this.image[i][j].r / max.r) << 16)
                | ((int) (255.f * this.image[i][j].g / max.g) << 8)
                | ((int) (255.f * this.image[i][j].b / max.b)));
    }
  }
示例#4
0
 public Color getColor(int x, int y) {
   Spectrum s = this.image[x][y];
   return new Color(s.getR(), s.getG(), s.getB());
 }
 /**
  * Convert a value in the range 0..1 to an RGB color.
  *
  * @param v a value in the range 0..1
  * @return an RGB color
  */
 public int getColor(float v) {
   return Spectrum.wavelengthToRGB(380 + 400 * ImageMath.clamp(v, 0, 1.0f));
 }