问:
parse text and get number of hours
i have a pandas dataframe with text attribute as

```<code>loc_id   text
1        'Monday: 8:30 AM \x96 5:30 PM,Tuesday: 8:30 AM \x96 5:30 PM,Wednesday: 8:30 AM \x96 5:30 PM,Thursday: 8:30 AM \x96 5:30 PM,Friday: 8:30 AM \x96 5:30 PM,Saturday: Closed,Sunday: Closed'
2         ''
3         'Monday: Open 24 hours,Tuesday: Open 24 hours,Wednesday: Open 24 hours,Thursday: Open 24 hours,Friday: Open 24 hours,Saturday: Open 24 hours,Sunday: Open 24 hours
</code>```

its a text data and i want to compute the total number of opening hours when it was open like this

```<code>loc_id      openingHours
1           45
2           NAN
3           168
</code>```

i am new to text mining so have no idea how to parse and convert it.The text only have these two formats as mentioned.

答:
I think you need some natural language date parser, for example dateparser:

dateparser provides modules to easily parse localized dates in almost
  any string formats commonly found on web pages.

Generic parsing of dates in English, Spanish, Dutch, Russian and over 20 other languages plus numerous formats in a language agnostic
  fashion.

Generic parsing of relative dates like: '1 min ago', '2 weeks ago', '3 months, 1 week and 1 day ago', 'in 2 days', 'tomorrow'.

Generic parsing of dates with time zones abbreviations or UTC offsets like: 'August 14, 2015 EST', 'July 4, 2013 PST', '21 July 2013
  10:15 pm +0500'.

Support for non-Gregorian calendar systems. See Supported Calendars.

Extensive test coverage.

If you need to parse it, then as @asongtoruin proposed, you have to use regular expressions:

```<code>import re
opened_str = 'Monday: 8:30 AM \x96 5:30 PM,Tuesday: 8:30 AM \x96 5:30 PM,Wednesday: 8:30 AM \x96 5:30 PM,Thursday: 8:30 AM \x96 5:30 PM,Friday: 8:30 AM \x96 5:30 PM,Saturday: Closed,Sunday: Closed'

PARSE_RE = re.compile(r'(?P<DAY>Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday): (?P<WORKHOURS>(?P<OPEN>\d+:\d+ (:?AM|PM)) \x96 (?P<CLOSE>\d+:\d+ (:?AM|PM))|Closed|Open 24 hours)')

for item in PARSE_RE.findall(opened_str):
    print(item)
</code>```

Which will print:

```<code>('Monday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Tuesday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Wednesday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Thursday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Friday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Saturday', 'Closed', '', '', '', '')
('Sunday', 'Closed', '', '', '', '')
</code>```

So you can check each tuple's 2nd and 3rd index for opened/closed times or 1st if it's closed. After that you can parse those dates how you like.

Title: parse text and get number of hours

Body:
i have a pandas dataframe with text attribute as

loc_id   text
1        'Monday: 8:30 AM \x96 5:30 PM,Tuesday: 8:30 AM \x96 5:30 PM,Wednesday: 8:30 AM \x96 5:30 PM,Thursday: 8:30 AM \x96 5:30 PM,Friday: 8:30 AM \x96 5:30 PM,Saturday: Closed,Sunday: Closed'
2         ''
3         'Monday: Open 24 hours,Tuesday: Open 24 hours,Wednesday: Open 24 hours,Thursday: Open 24 hours,Friday: Open 24 hours,Saturday: Open 24 hours,Sunday: Open 24 hours

its a text data and i want to compute the total number of opening hours when it was open like this

loc_id      openingHours
1           45
2           NAN
3           168

i am new to text mining so have no idea how to parse and convert it.The text only have these two formats as mentioned.

Body:
I think you need some natural language date parser, for example dateparser:

dateparser provides modules to easily parse localized dates in almost
  any string formats commonly found on web pages.

Generic parsing of dates in English, Spanish, Dutch, Russian and over 20 other languages plus numerous formats in a language agnostic
  fashion.

Generic parsing of relative dates like: '1 min ago', '2 weeks ago', '3 months, 1 week and 1 day ago', 'in 2 days', 'tomorrow'.

Generic parsing of dates with time zones abbreviations or UTC offsets like: 'August 14, 2015 EST', 'July 4, 2013 PST', '21 July 2013
  10:15 pm +0500'.

Support for non-Gregorian calendar systems. See Supported Calendars.

Extensive test coverage.

If you need to parse it, then as @asongtoruin proposed, you have to use regular expressions:

import re
opened_str = 'Monday: 8:30 AM \x96 5:30 PM,Tuesday: 8:30 AM \x96 5:30 PM,Wednesday: 8:30 AM \x96 5:30 PM,Thursday: 8:30 AM \x96 5:30 PM,Friday: 8:30 AM \x96 5:30 PM,Saturday: Closed,Sunday: Closed'

PARSE_RE = re.compile(r'(?P<DAY>Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday): (?P<WORKHOURS>(?P<OPEN>\d+:\d+ (:?AM|PM)) \x96 (?P<CLOSE>\d+:\d+ (:?AM|PM))|Closed|Open 24 hours)')

for item in PARSE_RE.findall(opened_str):
    print(item)

Which will print:

('Monday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Tuesday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Wednesday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Thursday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Friday', '8:30 AM \x96 5:30 PM', '8:30 AM', 'AM', '5:30 PM', 'PM')
('Saturday', 'Closed', '', '', '', '')
('Sunday', 'Closed', '', '', '', '')

So you can check each tuple's 2nd and 3rd index for opened/closed times or 1st if it's closed. After that you can parse those dates how you like.


来源: stackexchange

问:
router-view content not rendering
The router-view content of my app always remains empty () even though routing itself works perfectly and templates are correctly rendered throughout the app.

(Note: Even though there's just a import Vue from 'vue';, I'm using the standalone version of Vue.js with compilation support. The correct import is replaced by webpack.)

main.ts

```<code>import Vue from 'vue';
import Router from './services/router';
import { AppComponent } from './components/';

export default new Vue({
  el: '#app-container',
  router: Router,
  render: (context) => context(AppComponent)
});
</code>```

main.template.pug (excerpt)

```<code>body
  #app-container
</code>```

app.ts (excerpt)

```<code>@Component({
  template: require('./app.template.pug'),
  components: {
    'app-header': HeaderComponent,
    ...
  }
})
export class AppComponent extends Vue {

}
</code>```

app.template.pug

```<code>.app
  app-header
  .app-body
    app-sidebar
    main.app-content
      app-breadcrumb(:list='list')
      .container-fluid
        router-view
    app-aside
  app-footer
</code>```

services/router/index.ts (excerpt)

```<code>import Router from 'vue-router';
import { DashboardComponent } from '../../components/pages/dashboard';

Vue.use(Router);

export default new Router({
  mode: 'history',
  linkActiveClass: 'open active',
  routes: [
    {
      path: '/',
      redirect: '/dashboard',
      name: 'Home',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: DashboardComponent
        }
      ]
    }
  ]
});
</code>```

答: Alright, I figured it out myself. It seems like that every route definition within the vue-router requires a component. So it correctly routed to the DashboardComponent, but had nothing to render on it's parent. I provided a simple dummy component for the parent with just a router-view for it's template and it started working.

ContentLicense: CC BY-SA 3.0

Title: router-view content not rendering

Body:
The router-view content of my app always remains empty () even though routing itself works perfectly and templates are correctly rendered throughout the app.

(Note: Even though there's just a import Vue from 'vue';, I'm using the standalone version of Vue.js with compilation support. The correct import is replaced by webpack.)

main.ts

import Vue from 'vue';
import Router from './services/router';
import { AppComponent } from './components/';

export default new Vue({
  el: '#app-container',
  router: Router,
  render: (context) => context(AppComponent)
});

main.template.pug (excerpt)

body
  #app-container

app.ts (excerpt)

@Component({
  template: require('./app.template.pug'),
  components: {
    'app-header': HeaderComponent,
    ...
  }
})
export class AppComponent extends Vue {

}

app.template.pug

.app
  app-header
  .app-body
    app-sidebar
    main.app-content
      app-breadcrumb(:list='list')
      .container-fluid
        router-view
    app-aside
  app-footer

services/router/index.ts (excerpt)

import Router from 'vue-router';
import { DashboardComponent } from '../../components/pages/dashboard';

Vue.use(Router);

export default new Router({
  mode: 'history',
  linkActiveClass: 'open active',
  routes: [
    {
      path: '/',
      redirect: '/dashboard',
      name: 'Home',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: DashboardComponent
        }
      ]
    }
  ]
});


问:
Convert SVG polygon to a 3d polygon in svg not canvas
I have JSON data to generate some SVG (2D) polygons. I'm looking for a way to draw these polygons in SVG with three dimensions. I've found many libraries to draw 3D paths and polygons in canvas but I need SVG to have access to my polygons as a DOM object.
For better understanding, I want something like this but I want the output in SVG:
JSModeler

答:
Okay so i read up on 3D manipulation of 2D shapes and found this excellent tutorial for 3D Canvas animations that i managed to make an SVG version of:

/**
 * Point holds data for a "point-in-space" and handles any manipulations of said point, like rotation
 *
 * @class Point
 */
var Point = (function() {
  function Point(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }
  /**
   * Rotates on all axis
   *
   * @param {ICoord} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotate = function(angle) {
    return this
      .rotateX(angle.x)
      .rotateY(angle.y)
      .rotateZ(angle.y);
  };
  /**
   * Rotate on x axis
   *
   * @param {number} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotateX = function(angle) {
    var rad, cosa, sina, y, z;
    rad = angle * Math.PI / 180;
    cosa = Math.cos(rad);
    sina = Math.sin(rad);
    y = this.y * cosa - this.z * sina;
    z = this.y * sina + this.z * cosa;
    return new Point(this.x, y, z);
  };
  /**
   * Rotate on y axis
   *
   * @param {number} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotateY = function(angle) {
    var rad, cosa, sina, x, z;
    rad = angle * Math.PI / 180;
    cosa = Math.cos(rad);
    sina = Math.sin(rad);
    z = this.z * cosa - this.x * sina;
    x = this.z * sina + this.x * cosa;
    return new Point(x, this.y, z);
  };
  /**
   * Rotate on z axis
   *
   * @param {number} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotateZ = function(angle) {
    var rad, cosa, sina, x, y;
    rad = angle * Math.PI / 180;
    cosa = Math.cos(rad);
    sina = Math.sin(rad);
    x = this.x * cosa - this.y * sina;
    y = this.x * sina + this.y * cosa;
    return new Point(x, y, this.z);
  };
  return Point;
}());
/**
 * Face is a collection of point that produces a surface
 * A face should have at least 3 points(vertices)
 *
 *
 * @class Face
 */
var Face = (function() {
  function Face(name, vertices, color, svgElement) {
    if (vertices === void 0) {
      vertices = [];
    }
    if (color === void 0) {
      color = "rgba(0,0,255,0.5)";
    }
    if (svgElement === void 0) {
      svgElement = document.createElementNS('http://www.w3.org/2000/svg', "polygon");
    }
    this.name = name;
    this.vertices = vertices;
    this.color = color;
    this.svgElement = svgElement;
  }
  /**
   * Calculate all vertices positions and rebuild SVG polygon
   *
   * @param {ICoord} [angle={ x: 0, y: 0, z: 0 }]
   * @returns
   *
   * @memberOf Face
   */
  Face.prototype.render = function(angle) {
    if (angle === void 0) {
      angle = {
        x: 0,
        y: 0,
        z: 0
      };
    }
    this.svgElement.setAttribute("face-name", this.name);
    var points = [];
    for (var i = 0; i < this.vertices.length; i++) {
      var vert = this.vertices[i].rotate(angle);
      points.push(vert.x + ',' + vert.y);
    }
    this.svgElement.setAttribute("stroke", this.color);
    this.svgElement.setAttribute("fill", this.color);
    this.svgElement.setAttribute("points", points.join(" "));
    return this;
  };
  return Face;
}());
/**
 * Polygon is a collection of Faces that make up a shape, like a Box
 * Polygon manages 2D translation across the canvas and maintains shape-level data like the current angle
 *
 * @class Polygon
 */
var Polygon = (function() {
  function Polygon(faces, position, angle, svgElement) {
    if (faces === void 0) {
      faces = [];
    }
    if (position === void 0) {
      position = {
        x: 0,
        y: 0
      };
    }
    if (angle === void 0) {
      angle = {
        x: 0,
        y: 0,
        z: 0
      };
    }
    if (svgElement === void 0) {
      svgElement = document.createElementNS('http://www.w3.org/2000/svg', "g");
    }
    this.faces = faces;
    this.position = position;
    this.angle = angle;
    this.svgElement = svgElement;
  }
  /**
   * Renders all faces and translate across viewport
   *
   * @param {ICoord} [angle=this.angle]
   * @returns
   *
   * @memberOf Polygon
   */
  Polygon.prototype.render = function(angle) {
    if (angle === void 0) {
      angle = this.angle;
    }
    this.svgElement.innerHTML = '';
    for (var index = 0; index < this.faces.length; index++) {
      var face = this.faces[index];
      face.render(angle);
      this.svgElement.appendChild(face.svgElement);
    }
    this.svgElement.setAttribute("transform", "translate(" + this.position.x + "," + this.position.y + ")");
    return this;
  };
  return Polygon;
}());
/**
 * Box is a utility function that creates a cube Polygon
 *
 * @param {ICoord} [dimensions={ x: 100, y: 100, z: 100 }]
 * @param {ISimpleCoord} [position={ x: 0, y: 0 }]
 * @param {ICoord} [angle={ x: 0, y: 0, z: 0 }]
 * @returns
 */
function Box(dimensions, position, angle) {
  if (dimensions === void 0) {
    dimensions = {
      x: 100,
      y: 100,
      z: 100
    };
  }
  if (position === void 0) {
    position = {
      x: 0,
      y: 0
    };
  }
  if (angle === void 0) {
    angle = {
      x: 0,
      y: 0,
      z: 0
    };
  }
  return new Polygon([
    new Face("Back", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
    ]),
    new Face("Left", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
    ]),
    new Face("Right", [
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
    ]),
    new Face("Front", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
    ]),
    new Face("Top", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
    ]),
    new Face("Bottom", [
      new Point(-1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
    ]),
  ], position, angle);
}
/**
 * Like Box this returns a Polygon shape, this one in a Pyramid shape
 *
 * @param {ICoord} [dimensions={ x: 100, y: 100, z: 100 }]
 * @param {ISimpleCoord} [position={ x: 0, y: 0 }]
 * @param {ICoord} [angle={ x: 0, y: 0, z: 0 }]
 * @returns
 */
function Pyramid(dimensions, position, angle) {
  if (dimensions === void 0) {
    dimensions = {
      x: 100,
      y: 100,
      z: 100
    };
  }
  if (position === void 0) {
    position = {
      x: 0,
      y: 0
    };
  }
  if (angle === void 0) {
    angle = {
      x: 0,
      y: 0,
      z: 0
    };
  }
  return new Polygon([
    new Face("Top", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
    ]),
    new Face("Back", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
    new Face("Left", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
    new Face("Right", [
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
    new Face("Front", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
  ], position, angle);
}
/**
 * Viewport is the svg-layer where all polygons are drawn
 *
 * @class Viewport
 */
var Viewport = (function() {
  function Viewport(dimensions, polygons, svgElement) {
    if (dimensions === void 0) {
      dimensions = {
        x: 100,
        y: 100
      };
    }
    if (polygons === void 0) {
      polygons = [];
    }
    if (svgElement === void 0) {
      svgElement = document.createElementNS('http://www.w3.org/2000/svg', "svg");
    }
    this.dimensions = dimensions;
    this.polygons = polygons;
    this.svgElement = svgElement;
    this.svgElement.setAttribute("width", this.dimensions.x.toString());
    this.svgElement.setAttribute("height", this.dimensions.y.toString());
    this.svgElement.setAttribute("xmlns", 'http://www.w3.org/2000/svg');
  }
  return Viewport;
}());
//TEST
var view = new Viewport({
  x: 700,
  y: 400
});
var box = Box({
    x: 100,
    y: 100,
    z: 100
  }, {
    x: 200,
    y: 200
  })
  .render();
var pyramid = Pyramid({
    x: 100,
    y: 100,
    z: 100
  }, {
    x: 500,
    y: 200
  }, {
    x: 180,
    y: 0,
    z: 0
  })
  .render();
//append to DOM
document.body.appendChild(view.svgElement);
view.svgElement.appendChild(box.svgElement);
view.svgElement.appendChild(pyramid.svgElement);
//Animate
setInterval(function() {
  box.angle.x++;
  box.angle.y++;
  box.angle.z++;
  box.render();
  pyramid.angle.x++;
  pyramid.angle.y++;
  pyramid.angle.z++;
  pyramid.render();
}, 1000 / 24);```

From here you should be able to produce most any shape in 3D space yourself.

Body:
Okay so i read up on 3D manipulation of 2D shapes and found this excellent tutorial for 3D Canvas animations that i managed to make an SVG version of:

/**
 * Point holds data for a "point-in-space" and handles any manipulations of said point, like rotation
 *
 * @class Point
 */
var Point = (function() {
  function Point(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }
  /**
   * Rotates on all axis
   *
   * @param {ICoord} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotate = function(angle) {
    return this
      .rotateX(angle.x)
      .rotateY(angle.y)
      .rotateZ(angle.y);
  };
  /**
   * Rotate on x axis
   *
   * @param {number} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotateX = function(angle) {
    var rad, cosa, sina, y, z;
    rad = angle * Math.PI / 180;
    cosa = Math.cos(rad);
    sina = Math.sin(rad);
    y = this.y * cosa - this.z * sina;
    z = this.y * sina + this.z * cosa;
    return new Point(this.x, y, z);
  };
  /**
   * Rotate on y axis
   *
   * @param {number} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotateY = function(angle) {
    var rad, cosa, sina, x, z;
    rad = angle * Math.PI / 180;
    cosa = Math.cos(rad);
    sina = Math.sin(rad);
    z = this.z * cosa - this.x * sina;
    x = this.z * sina + this.x * cosa;
    return new Point(x, this.y, z);
  };
  /**
   * Rotate on z axis
   *
   * @param {number} angle
   * @returns
   *
   * @memberOf Point
   */
  Point.prototype.rotateZ = function(angle) {
    var rad, cosa, sina, x, y;
    rad = angle * Math.PI / 180;
    cosa = Math.cos(rad);
    sina = Math.sin(rad);
    x = this.x * cosa - this.y * sina;
    y = this.x * sina + this.y * cosa;
    return new Point(x, y, this.z);
  };
  return Point;
}());
/**
 * Face is a collection of point that produces a surface
 * A face should have at least 3 points(vertices)
 *
 *
 * @class Face
 */
var Face = (function() {
  function Face(name, vertices, color, svgElement) {
    if (vertices === void 0) {
      vertices = [];
    }
    if (color === void 0) {
      color = "rgba(0,0,255,0.5)";
    }
    if (svgElement === void 0) {
      svgElement = document.createElementNS('http://www.w3.org/2000/svg', "polygon");
    }
    this.name = name;
    this.vertices = vertices;
    this.color = color;
    this.svgElement = svgElement;
  }
  /**
   * Calculate all vertices positions and rebuild SVG polygon
   *
   * @param {ICoord} [angle={ x: 0, y: 0, z: 0 }]
   * @returns
   *
   * @memberOf Face
   */
  Face.prototype.render = function(angle) {
    if (angle === void 0) {
      angle = {
        x: 0,
        y: 0,
        z: 0
      };
    }
    this.svgElement.setAttribute("face-name", this.name);
    var points = [];
    for (var i = 0; i < this.vertices.length; i++) {
      var vert = this.vertices[i].rotate(angle);
      points.push(vert.x + ',' + vert.y);
    }
    this.svgElement.setAttribute("stroke", this.color);
    this.svgElement.setAttribute("fill", this.color);
    this.svgElement.setAttribute("points", points.join(" "));
    return this;
  };
  return Face;
}());
/**
 * Polygon is a collection of Faces that make up a shape, like a Box
 * Polygon manages 2D translation across the canvas and maintains shape-level data like the current angle
 *
 * @class Polygon
 */
var Polygon = (function() {
  function Polygon(faces, position, angle, svgElement) {
    if (faces === void 0) {
      faces = [];
    }
    if (position === void 0) {
      position = {
        x: 0,
        y: 0
      };
    }
    if (angle === void 0) {
      angle = {
        x: 0,
        y: 0,
        z: 0
      };
    }
    if (svgElement === void 0) {
      svgElement = document.createElementNS('http://www.w3.org/2000/svg', "g");
    }
    this.faces = faces;
    this.position = position;
    this.angle = angle;
    this.svgElement = svgElement;
  }
  /**
   * Renders all faces and translate across viewport
   *
   * @param {ICoord} [angle=this.angle]
   * @returns
   *
   * @memberOf Polygon
   */
  Polygon.prototype.render = function(angle) {
    if (angle === void 0) {
      angle = this.angle;
    }
    this.svgElement.innerHTML = '';
    for (var index = 0; index < this.faces.length; index++) {
      var face = this.faces[index];
      face.render(angle);
      this.svgElement.appendChild(face.svgElement);
    }
    this.svgElement.setAttribute("transform", "translate(" + this.position.x + "," + this.position.y + ")");
    return this;
  };
  return Polygon;
}());
/**
 * Box is a utility function that creates a cube Polygon
 *
 * @param {ICoord} [dimensions={ x: 100, y: 100, z: 100 }]
 * @param {ISimpleCoord} [position={ x: 0, y: 0 }]
 * @param {ICoord} [angle={ x: 0, y: 0, z: 0 }]
 * @returns
 */
function Box(dimensions, position, angle) {
  if (dimensions === void 0) {
    dimensions = {
      x: 100,
      y: 100,
      z: 100
    };
  }
  if (position === void 0) {
    position = {
      x: 0,
      y: 0
    };
  }
  if (angle === void 0) {
    angle = {
      x: 0,
      y: 0,
      z: 0
    };
  }
  return new Polygon([
    new Face("Back", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
    ]),
    new Face("Left", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
    ]),
    new Face("Right", [
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
    ]),
    new Face("Front", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
    ]),
    new Face("Top", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
    ]),
    new Face("Bottom", [
      new Point(-1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, 1 * dimensions.y, 1 * dimensions.z),
    ]),
  ], position, angle);
}
/**
 * Like Box this returns a Polygon shape, this one in a Pyramid shape
 *
 * @param {ICoord} [dimensions={ x: 100, y: 100, z: 100 }]
 * @param {ISimpleCoord} [position={ x: 0, y: 0 }]
 * @param {ICoord} [angle={ x: 0, y: 0, z: 0 }]
 * @returns
 */
function Pyramid(dimensions, position, angle) {
  if (dimensions === void 0) {
    dimensions = {
      x: 100,
      y: 100,
      z: 100
    };
  }
  if (position === void 0) {
    position = {
      x: 0,
      y: 0
    };
  }
  if (angle === void 0) {
    angle = {
      x: 0,
      y: 0,
      z: 0
    };
  }
  return new Polygon([
    new Face("Top", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
    ]),
    new Face("Back", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
    new Face("Left", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
    new Face("Right", [
      new Point(1 * dimensions.x, -1 * dimensions.y, -1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
    new Face("Front", [
      new Point(-1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(1 * dimensions.x, -1 * dimensions.y, 1 * dimensions.z),
      new Point(0, 1 * dimensions.y, 0),
    ]),
  ], position, angle);
}
/**
 * Viewport is the svg-layer where all polygons are drawn
 *
 * @class Viewport
 */
var Viewport = (function() {
  function Viewport(dimensions, polygons, svgElement) {
    if (dimensions === void 0) {
      dimensions = {
        x: 100,
        y: 100
      };
    }
    if (polygons === void 0) {
      polygons = [];
    }
    if (svgElement === void 0) {
      svgElement = document.createElementNS('http://www.w3.org/2000/svg', "svg");
    }
    this.dimensions = dimensions;
    this.polygons = polygons;
    this.svgElement = svgElement;
    this.svgElement.setAttribute("width", this.dimensions.x.toString());
    this.svgElement.setAttribute("height", this.dimensions.y.toString());
    this.svgElement.setAttribute("xmlns", 'http://www.w3.org/2000/svg');
  }
  return Viewport;
}());
//TEST
var view = new Viewport({
  x: 700,
  y: 400
});
var box = Box({
    x: 100,
    y: 100,
    z: 100
  }, {
    x: 200,
    y: 200
  })
  .render();
var pyramid = Pyramid({
    x: 100,
    y: 100,
    z: 100
  }, {
    x: 500,
    y: 200
  }, {
    x: 180,
    y: 0,
    z: 0
  })
  .render();
//append to DOM
document.body.appendChild(view.svgElement);
view.svgElement.appendChild(box.svgElement);
view.svgElement.appendChild(pyramid.svgElement);
//Animate
setInterval(function() {
  box.angle.x++;
  box.angle.y++;
  box.angle.z++;
  box.render();
  pyramid.angle.x++;
  pyramid.angle.y++;
  pyramid.angle.z++;
  pyramid.render();
}, 1000 / 24);

From here you should be able to produce most any shape in 3D space yourself.


问:
Attaching a property to a javsacript function - Where does the property gets linked?
Please take a look at this following nsnippet of simple code:-

```<code>function Fis(){
}

Fis.num =20;//no errors
console.log(Fis.num);//prints  20
</code>```

Now, I know that the Fis function is implicitly(from the very beginning) linked to  an object through "Fis.prototype" link.

In the code Fis.num = 20 is getting executed without any errors. Where is this num property getting linked ?

答: Your Fis() function is actually an object to which you can assign properties. In your case you define the num property with value 20 to Fis. So you link this property when you assign it to Fis with Fis.num=20. Therefore you can get the property value by Fis.num.

Body:
Please take a look at this following nsnippet of simple code:-

function Fis(){
}

Fis.num =20;//no errors
console.log(Fis.num);//prints  20

Now, I know that the Fis function is implicitly(from the very beginning) linked to  an object through "Fis.prototype" link.

In the code Fis.num = 20 is getting executed without any errors. Where is this num property getting linked ?


问:
Class with two constructors taking different objects as parents
I want to create a new class, which has to be able to take two different types of objects (with nearly the same functions and variables). I am trying to use two constructors for this. Since both possible argument classes have nearly the same variables in them, I want to refer to them with the same variable named parent.

What I tried:

class Segment{
  float phi;
  float theta;
  float len;
  Base parent;
  Segment parent;

  public Segment(Base parent, float len, float phi, float theta) {
    this.len = len;
    this.phi = phi;
    this.theta = theta;

    this.parent = parent;
  }

  public Segment(Segment parent, float len, float phi, float theta) {
    this.len = len;
    this.phi = phi;
    this.theta = theta;

    this.parent = parent;
  }

  // ... functions calling parent.variableName
}
```

This is not possible because parent is a duplicate, what would be a way to solve this?

Edit

The only thing Segment and Base have in common are some variables telling the start end end points, to connect new Segments to.
Other than that the Base is standing still, and the Segment's are moving

答:
The OO way to do this is to create a common super class for both classes:

```<code>public abstract class Super {
    // Here you declare all fields and methods that your classes have in common.
}

public final class Base extends Super { ... }
public final class Segment extends Super { ... }
</code>```

Then your class looks like this:

```<code>public final class YourClass {
    ...
    private final Super parent; // only once
    public YourClass(Super parent, ...) {
        ...
        this.parent = parent;
    }
}
</code>```

That is, you only have one constructor and one field referring to the super class.

Body:
I want to create a new class, which has to be able to take two different types of objects (with nearly the same functions and variables). I am trying to use two constructors for this. Since both possible argument classes have nearly the same variables in them, I want to refer to them with the same variable named parent.

What I tried:

class Segment{
  float phi;
  float theta;
  float len;
  Base parent;
  Segment parent;

  public Segment(Base parent, float len, float phi, float theta) {
    this.len = len;
    this.phi = phi;
    this.theta = theta;

    this.parent = parent;
  }

  public Segment(Segment parent, float len, float phi, float theta) {
    this.len = len;
    this.phi = phi;
    this.theta = theta;

    this.parent = parent;
  }

  // ... functions calling parent.variableName
}

This is not possible because parent is a duplicate, what would be a way to solve this?

Edit

The only thing Segment and Base have in common are some variables telling the start end end points, to connect new Segments to.
Other than that the Base is standing still, and the Segment's are moving

Body:
The OO way to do this is to create a common super class for both classes:

public abstract class Super {
    // Here you declare all fields and methods that your classes have in common.
}

public final class Base extends Super { ... }
public final class Segment extends Super { ... }

Then your class looks like this:

public final class YourClass {
    ...
    private final Super parent; // only once
    public YourClass(Super parent, ...) {
        ...
        this.parent = parent;
    }
}

That is, you only have one constructor and one field referring to the super class.


问:
Error While retrieving DICOM image from PACS server
I am trying to retrieve DICOM images from PACS server, I get DICOM object using dcmqr.get and convert it to byte array, and when I pass byte array of DICOM object to getPixelDataAsBufferedImage method its gives exception java.lang.ArrayIndexOutOfBoundsException: 0 at line 'buff = reader.read(0, param);'.

I am very new in DICOM, not getting exactly what is the issue. Is there any problem in making query to get DICOM or any problem in converting byte array to buffered image ?

```<code>public class TestDCM {

public static DcmQR dcmqr;

public static void main(String[] args) {

    dcmqr = new DcmQR("DCM4CHEE");
    dcmqr.setCalledAET("DCM4CHEE", true);
    dcmqr.setRemoteHost("IP address");
    dcmqr.setRemotePort(11112);

    dcmqr.setDateTimeMatching(true);
    //dcmqr.setCFind(true);
    dcmqr.setCGet(true);
    dcmqr.configureTransferCapability(true);

    dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.IMAGE);

    dcmqr.addMatchingKey(Tag.toTagPath("SOPClassUID"),
            "1.2.840.10008.5.1.4.1.1.12.2");

    List<DicomObject> result = null;
    byte[] imgTab = null;
    BufferedImage bImage = null;
    try {
        dcmqr.start();
        System.out.println("started");
        dcmqr.open();
        System.out.println("opened");
        result = dcmqr.query();
        System.out.println("queried");
        dcmqr.get(result);
        System.out.println("List Size = " + result.size());

        for (DicomObject dco : result) {
            dco.putString(Tag.TransferSyntaxUID, VR.UI,UID.ImplicitVRLittleEndian);
            // convert dicom object to byte array
            imgTab = toByteArray(dco);
            // convert byte array to BufferedImage
            bImage = getPixelDataAsBufferedImage(imgTab);
            File file = new File("filepath.jpg");
            writeBufferedImage(file, bImage);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        if (dcmqr != null) {
            dcmqr.stop();
            dcmqr.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("done");
}
}

// toByteArray method
public static byte[] toByteArray(DicomObject obj) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(baos);
    DicomOutputStream dos = new DicomOutputStream(bos);
    dos.writeDicomFile(obj);
    dos.close();
    byte[] data = baos.toByteArray();
    return data;
}

//getPixelDataAsBufferedImage method
public static BufferedImage getPixelDataAsBufferedImage(byte[] dicomData)
        throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(dicomData);
    BufferedImage buff = null;
    Iterator<ImageReader> iter = ImageIO
            .getImageReadersByFormatName("DICOM");
    ImageReader reader = (ImageReader) iter.next();
    DicomImageReadParam param = (DicomImageReadParam) reader
            .getDefaultReadParam();
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    reader.setInput(iis, false);
    buff = reader.read(0, param);
    iis.close();
    if (buff == null)
        throw new IOException(
                "Could not read Dicom file. Maybe pixel data is invalid.");
    return buff;
}

//writeBufferedImage method
public static void writeBufferedImage(File file , BufferedImage bufferedImage){
    try {
        ImageIO.write(bufferedImage, "jpg", file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Jpeg image created successfully.");
}
</code>```

答:
I was successfully retrieve and convert DICOM. I am sharing the complete steps to retrieve and convert. It will help others too.

```<code>//Step 1: Retrieve DICOM

// Transfer Syntax
String[] DEF_TS = {
    UID.JPEGLossless,
    UID.JPEGLosslessNonHierarchical14, UID.JPEGLSLossless,
    UID.JPEGLSLossyNearLossless, UID.JPEG2000LosslessOnly,
    UID.JPEG2000, UID.JPEGBaseline1, UID.JPEGExtended24, UID.MPEG2,
    UID.DeflatedExplicitVRLittleEndian, UID.ExplicitVRBigEndian,
    UID.ExplicitVRLittleEndian, UID.ImplicitVRLittleEndian
};

DcmQR dcmqr = new DcmQR();

/* Set remote PACS server parameter */
dcmqr.setCalledAET("[Called AET]", false); //AET, host and port configured in PACS server
dcmqr.setRemoteHost("[PACS server host]");
dcmqr.setRemotePort("[Pacs server port]");

/* Set local port to listen */
dcmqr.setCalling("Receiving AET"); //Receiving AET, host and port should be configured in PACS server in association
dcmqr.setLocalHost("Receiving host(Local server host)");
dcmqr.setLocalPort("Receiving port(Local server post)");

// Set user detail
UserIdentity dcmuserId = new UserIdentity.UsernamePasscode(userId,
pin.toCharArray());
dcmuserId.setPositiveResponseRequested(true);
dcmqr.setUserIdentity(dcmuserId);

// Add Transfer syntax UID
dcmqr.addStoreTransferCapability("1.2.840.10008.5.1.4.1.1.1", DEF_TS); // CR
dcmqr.addStoreTransferCapability("1.2.840.10008.5.1.4.1.1.2", DEF_TS); // CT
dcmqr.addStoreTransferCapability("1.2.840.10008.5.1.4.1.1.4", DEF_TS); // MR/MRI
//.... Add all UID as required

dcmqr.setEvalRetrieveAET(true);

dcmqr.setCFind(true);

dcmqr.setCGet(true);

dcmqr.setMoveDest([Receving AE]);

dcmqr.configureTransferCapability(true);

// Set complete destination directory path, Where you want to store DICOMs
dcmqr.setStoreDestination("[dicomFilePath]");

dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.STUDY);

dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.SERIES);

dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.IMAGE);

dcmqr.addMatchingKey(Tag.toTagPath("StudyID"), [study id]); // other filters also can be add here

dcmqr.addReturnKey(Tag.toTagPath("SeriesNumber"));

dcmqr.start();
dcmqr.open();
List<DicomObject> result = dcmqr.query();
dcmqr.move(result);
// Here found dicoms with matching criteria will move from PACS server to your machine in provided destination path.

//step 2: DICOM file to DICOM object
DicomInputStream din = new DicomInputStream("dicom file path");
DicomObject dicomObject = din.readDicomObject();

//step 3: Convert DICOM to JPEG
byte[] imgTab = toByteArray(dicomObject); // See in question
/* create buffered image from byte array */
BufferedImage bufferedImage = getPixelDataAsBufferedImage(imgTab); // See in question
File outPutFile = new File("JPEG file path");
/* creating jpeg image from buffered image */
ImageIO.write(bufferedImage, "jpeg", outPutFile);
</code>```

Your JPEG is ready. Cheers

Body:
I am trying to retrieve DICOM images from PACS server, I get DICOM object using dcmqr.get and convert it to byte array, and when I pass byte array of DICOM object to getPixelDataAsBufferedImage method its gives exception java.lang.ArrayIndexOutOfBoundsException: 0 at line 'buff = reader.read(0, param);'.

I am very new in DICOM, not getting exactly what is the issue. Is there any problem in making query to get DICOM or any problem in converting byte array to buffered image ?

public class TestDCM {

public static DcmQR dcmqr;

public static void main(String[] args) {

    dcmqr = new DcmQR("DCM4CHEE");
    dcmqr.setCalledAET("DCM4CHEE", true);
    dcmqr.setRemoteHost("IP address");
    dcmqr.setRemotePort(11112);

    dcmqr.setDateTimeMatching(true);
    //dcmqr.setCFind(true);
    dcmqr.setCGet(true);
    dcmqr.configureTransferCapability(true);

    dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.IMAGE);

    dcmqr.addMatchingKey(Tag.toTagPath("SOPClassUID"),
            "1.2.840.10008.5.1.4.1.1.12.2");

    List<DicomObject> result = null;
    byte[] imgTab = null;
    BufferedImage bImage = null;
    try {
        dcmqr.start();
        System.out.println("started");
        dcmqr.open();
        System.out.println("opened");
        result = dcmqr.query();
        System.out.println("queried");
        dcmqr.get(result);
        System.out.println("List Size = " + result.size());

        for (DicomObject dco : result) {
            dco.putString(Tag.TransferSyntaxUID, VR.UI,UID.ImplicitVRLittleEndian);
            // convert dicom object to byte array
            imgTab = toByteArray(dco);
            // convert byte array to BufferedImage
            bImage = getPixelDataAsBufferedImage(imgTab);
            File file = new File("filepath.jpg");
            writeBufferedImage(file, bImage);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        if (dcmqr != null) {
            dcmqr.stop();
            dcmqr.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("done");
}
}

// toByteArray method
public static byte[] toByteArray(DicomObject obj) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(baos);
    DicomOutputStream dos = new DicomOutputStream(bos);
    dos.writeDicomFile(obj);
    dos.close();
    byte[] data = baos.toByteArray();
    return data;
}

//getPixelDataAsBufferedImage method
public static BufferedImage getPixelDataAsBufferedImage(byte[] dicomData)
        throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(dicomData);
    BufferedImage buff = null;
    Iterator<ImageReader> iter = ImageIO
            .getImageReadersByFormatName("DICOM");
    ImageReader reader = (ImageReader) iter.next();
    DicomImageReadParam param = (DicomImageReadParam) reader
            .getDefaultReadParam();
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    reader.setInput(iis, false);
    buff = reader.read(0, param);
    iis.close();
    if (buff == null)
        throw new IOException(
                "Could not read Dicom file. Maybe pixel data is invalid.");
    return buff;
}

//writeBufferedImage method
public static void writeBufferedImage(File file , BufferedImage bufferedImage){
    try {
        ImageIO.write(bufferedImage, "jpg", file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Jpeg image created successfully.");
}

Body:
I was successfully retrieve and convert DICOM. I am sharing the complete steps to retrieve and convert. It will help others too.

//Step 1: Retrieve DICOM

// Transfer Syntax
String[] DEF_TS = {
    UID.JPEGLossless,
    UID.JPEGLosslessNonHierarchical14, UID.JPEGLSLossless,
    UID.JPEGLSLossyNearLossless, UID.JPEG2000LosslessOnly,
    UID.JPEG2000, UID.JPEGBaseline1, UID.JPEGExtended24, UID.MPEG2,
    UID.DeflatedExplicitVRLittleEndian, UID.ExplicitVRBigEndian,
    UID.ExplicitVRLittleEndian, UID.ImplicitVRLittleEndian
};

DcmQR dcmqr = new DcmQR();

/* Set remote PACS server parameter */
dcmqr.setCalledAET("[Called AET]", false); //AET, host and port configured in PACS server
dcmqr.setRemoteHost("[PACS server host]");
dcmqr.setRemotePort("[Pacs server port]");

/* Set local port to listen */
dcmqr.setCalling("Receiving AET"); //Receiving AET, host and port should be configured in PACS server in association
dcmqr.setLocalHost("Receiving host(Local server host)");
dcmqr.setLocalPort("Receiving port(Local server post)");

// Set user detail
UserIdentity dcmuserId = new UserIdentity.UsernamePasscode(userId,
pin.toCharArray());
dcmuserId.setPositiveResponseRequested(true);
dcmqr.setUserIdentity(dcmuserId);

// Add Transfer syntax UID
dcmqr.addStoreTransferCapability("1.2.840.10008.5.1.4.1.1.1", DEF_TS); // CR
dcmqr.addStoreTransferCapability("1.2.840.10008.5.1.4.1.1.2", DEF_TS); // CT
dcmqr.addStoreTransferCapability("1.2.840.10008.5.1.4.1.1.4", DEF_TS); // MR/MRI
//.... Add all UID as required

dcmqr.setEvalRetrieveAET(true);

dcmqr.setCFind(true);

dcmqr.setCGet(true);

dcmqr.setMoveDest([Receving AE]);

dcmqr.configureTransferCapability(true);

// Set complete destination directory path, Where you want to store DICOMs
dcmqr.setStoreDestination("[dicomFilePath]");

dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.STUDY);

dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.SERIES);

dcmqr.setQueryLevel(DcmQR.QueryRetrieveLevel.IMAGE);

dcmqr.addMatchingKey(Tag.toTagPath("StudyID"), [study id]); // other filters also can be add here

dcmqr.addReturnKey(Tag.toTagPath("SeriesNumber"));

dcmqr.start();
dcmqr.open();
List<DicomObject> result = dcmqr.query();
dcmqr.move(result);
// Here found dicoms with matching criteria will move from PACS server to your machine in provided destination path.

//step 2: DICOM file to DICOM object
DicomInputStream din = new DicomInputStream("dicom file path");
DicomObject dicomObject = din.readDicomObject();

//step 3: Convert DICOM to JPEG
byte[] imgTab = toByteArray(dicomObject); // See in question
/* create buffered image from byte array */
BufferedImage bufferedImage = getPixelDataAsBufferedImage(imgTab); // See in question
File outPutFile = new File("JPEG file path");
/* creating jpeg image from buffered image */
ImageIO.write(bufferedImage, "jpeg", outPutFile);

Your JPEG is ready. Cheers