Skip to content

Commit

Permalink
lots of restructure to be done in this branch, aborting
Browse files Browse the repository at this point in the history
  • Loading branch information
sagnik committed Aug 18, 2016
1 parent 93a7e59 commit aac03dd
Show file tree
Hide file tree
Showing 25 changed files with 310 additions and 344 deletions.
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ name := "pdsimplify"
lazy val root = project
.in(file("."))
.aggregate(
schema,
rectangle,
pdsimplifyparser,
writers
)
.settings(publishArtifact := false)

lazy val schema = project
.in(file("schema"))
lazy val rectangle = project
.in(file("rectangle"))
.settings(publishArtifact := false)

lazy val pdsimplifyparser = project
.in(file("pdsimplifyparser"))
.dependsOn(schema)
.dependsOn(rectangle)
.settings(publishArtifact := true)

lazy val writers = project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package edu.psu.sagnik.research.pdsimplify.impl

import java.io.File

import edu.psu.sagnik.research.pdsimplify.model.{ PDDocumentSimple, PDPageSimple, Rectangle }
import edu.psu.sagnik.research.data.RectangleOTL
import edu.psu.sagnik.research.pdsimplify.model.{PDDocumentSimple, PDPageSimple}
import edu.psu.sagnik.research.pdsimplify.path.impl.ProcessPaths
import edu.psu.sagnik.research.pdsimplify.raster.impl.ProcessRaster
import edu.psu.sagnik.research.pdsimplify.text.impl.ProcessText
import org.apache.pdfbox.pdmodel.{ PDDocument, PDPage }
import org.apache.pdfbox.pdmodel.{PDDocument, PDPage}

import scala.util.Try

Expand All @@ -32,11 +33,11 @@ object ProcessDocument {
gPaths = pdGraphicsPaths,
rasters = rasters,
bb =
Rectangle(
page.getBBox.getLowerLeftX,
page.getBBox.getUpperRightY,
page.getBBox.getUpperRightX,
page.getBBox.getLowerLeftY
RectangleOTL(
xTopLeft=page.getBBox.getLowerLeftX,
yTopLeft=page.getBBox.getUpperRightY,
widthRight=page.getBBox.getWidth,
heightDown=page.getBBox.getHeight
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.psu.sagnik.research.pdsimplify.model

import edu.psu.sagnik.research.data.RectangleOTL
import edu.psu.sagnik.research.pdsimplify.path.model.PDPath
import edu.psu.sagnik.research.pdsimplify.raster.model.PDRasterImage
import edu.psu.sagnik.research.pdsimplify.text.model.PDParagraph
Expand All @@ -15,7 +16,7 @@ case class PDPageSimple(
paragraphs: List[PDParagraph],
gPaths: List[PDPath],
rasters: List[PDRasterImage],
bb: Rectangle
bb: RectangleOTL
)

case class PDDocumentSimple(pages: List[PDPageSimple])

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import sun.java2d.loops.ProcessPath
*/

object BB {

def Line(p0: Point2D.Float, p1: Point2D.Float) = {
val xs = List(p0.x, p1.x)
val ys = List(p0.y, p1.y)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package edu.psu.sagnik.research.pdsimplify.rectangle

import edu.psu.sagnik.research.data.RectangleOTL

/**
* Created by schoudhury on 8/18/16.
*/
object RectangleHelpers {
implicit def round(x:Float)=scala.math.round(x)

/**
* Evaluates to a string that contains the Rectangle's
* point information as x1,y2,x2,y2 .
*/
def asCoordinatesStr(r: RectangleOTL): String =
s"[topLeftX]:${r.xTopLeft},[topLeftY]:${r.yTopLeft},[width]:${r.widthRight},[height]:${r.heightDown}"


//a bit of caution: this works only for axes parallel rectangles.
// That suffice for our purpose, but this isn't a generic method.
def rectDistance(r1:Rectangle,r2:Rectangle):Float={
val dy1=if (r1.y2<r2.y1) r2.y1-r1.y2 else 0
val dy2=if (r1.y1>r2.y2) r1.y1-r2.y2 else 0
val dx1=if (r1.x2<r2.x1) r2.x1-r1.x2 else 0
val dx2=if (r1.x1>r2.x2) r1.x1-r2.x2 else 0
dx1+dx2+dy1+dy2
}

def rectExtend(r:Rectangle,rs:Seq[Rectangle],checkAgainstRS:Seq[Rectangle],pageBB:Rectangle,direction:String):Option[Rectangle]=
if (
!rs.exists(a=>rectInterSects(a,r)) && //haven't found any intersection with body or caption text boxes
(r.x1>pageBB.x1 && r.x2<pageBB.x2 && r.y1>pageBB.y1 && r.y2 < pageBB.y2) // all coordinates OK with pageBB
)
rectExtend(changeRect(r,1f,direction),rs,checkAgainstRS,pageBB,direction)
else {
if (checkAgainstRS.filter(a=>rectInterSects(Rectangle(r.x1+2,r.y1+2,r.x2-2,r.y2-2),a)).length>2 //we have got an extended rectangle.
// Need to see if this is empty, or has a very small size
&& (r.x2-r.x1>10f && r.y2-r.y1> 10f)
)
Some(changeRect(r,-1f,direction))
else
None
}

def changeRect(r:Rectangle,changeparam:Float,direction:String):Rectangle=
direction match {
case "left" => r.copy(x1 = r.x1 - changeparam)
case "right" => r.copy(x2 = r.x2 + changeparam)
case "top" => r.copy(y2 = r.y2 + changeparam)
case "down" => r.copy(y1 = r.y1 - changeparam)
case _ => r
}


/*
TODO: test these methods
* */
def rectVerticalDistance(r1:Rectangle,r2:Rectangle):Float={
val dy1=if (r1.y2<r2.y1) r2.y1-r1.y2 else 0
val dy2=if (r1.y1>r2.y2) r1.y1-r2.y2 else 0
dy1+dy2
}

def rectHorizontalDistance(r1:Rectangle,r2:Rectangle):Float={
val dx1=if (r1.x2<r2.x1) r2.x1-r1.x2 else 0
val dx2=if (r1.x1>r2.x2) r1.x1-r2.x2 else 0
dx1+dx2
}

}
2 changes: 1 addition & 1 deletion schema/build.sbt → rectangle/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ lazy val scalaMacros = "org.scalamacros" % "paradise" % "2.1.0" cross CrossVersi
addCompilerPlugin(scalaMacros)

lazy val nitroOss = "com.gonitro"
lazy val avroCodegen = nitroOss %% "avro-codegen-runtime" % "0.3.5"
lazy val avroCodegen = nitroOss %% "avro-codegen-runtime" % "0.3.4"
lazy val shapeless = "com.chuusai" %% "shapeless" % "2.2.5"

libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package edu.psu.sagnik.research.pdsimplify.rectanglehelpers

import edu.psu.sagnik.research.data.RectangleOTL

/**
* Created by schoudhury on 8/18/16.
*/
object RectangleHelpers {

def round(x:Float)=scala.math.round(x)

/**
* Evaluates to a string that contains the Rectangle's
* point information as x1,y2,x2,y2 .
*/
def asCoordinatesStr(r: RectangleOTL): String =
s"[topLeftX]:${r.xTopLeft},[topLeftY]:${r.yTopLeft},[width]:${r.widthRight},[height]:${r.heightDown}"


//a bit of caution: this works only for axes parallel rectangles.
// That suffice for our purpose, but this isn't a generic method.
def rectDistance(r1:RectangleOTL,r2:RectangleOTL):Float={
val dy1=if (r1.y2<r2.y1) r2.y1-r1.y2 else 0
val dy2=if (r1.y1>r2.y2) r1.y1-r2.y2 else 0
val dx1=if (r1.x2<r2.x1) r2.x1-r1.x2 else 0
val dx2=if (r1.x1>r2.x2) r1.x1-r2.x2 else 0
dx1+dx2+dy1+dy2
}

def rectExtend(r:Rectangle,rs:Seq[Rectangle],checkAgainstRS:Seq[Rectangle],pageBB:Rectangle,direction:String):Option[Rectangle]=
if (
!rs.exists(a=>rectInterSects(a,r)) && //haven't found any intersection with body or caption text boxes
(r.x1>pageBB.x1 && r.x2<pageBB.x2 && r.y1>pageBB.y1 && r.y2 < pageBB.y2) // all coordinates OK with pageBB
)
rectExtend(changeRect(r,1f,direction),rs,checkAgainstRS,pageBB,direction)
else {
if (checkAgainstRS.filter(a=>rectInterSects(Rectangle(r.x1+2,r.y1+2,r.x2-2,r.y2-2),a)).length>2 //we have got an extended rectangle.
// Need to see if this is empty, or has a very small size
&& (r.x2-r.x1>10f && r.y2-r.y1> 10f)
)
Some(changeRect(r,-1f,direction))
else
None
}

def changeRect(r:Rectangle,changeparam:Float,direction:String):Rectangle=
direction match {
case "left" => r.copy(x1 = r.x1 - changeparam)
case "right" => r.copy(x2 = r.x2 + changeparam)
case "top" => r.copy(y2 = r.y2 + changeparam)
case "down" => r.copy(y1 = r.y1 - changeparam)
case _ => r
}


/*
TODO: test these methods
* */
def rectVerticalDistance(r1:Rectangle,r2:Rectangle):Float={
val dy1=if (r1.y2<r2.y1) r2.y1-r1.y2 else 0
val dy2=if (r1.y1>r2.y2) r1.y1-r2.y2 else 0
dy1+dy2
}

def rectHorizontalDistance(r1:Rectangle,r2:Rectangle):Float={
val dx1=if (r1.x2<r2.x1) r2.x1-r1.x2 else 0
val dx2=if (r1.x1>r2.x2) r1.x1-r2.x2 else 0
dx1+dx2
}

}
*/

0 comments on commit aac03dd

Please sign in to comment.