Blog

Bounding Box splitting script

· Construkted Reality

When using Reality Capture, sometimes I’ve needed to break apart the model into smaller sections. This may be useful if you want to process smaller chunks, or if you can’t texture a full mesh, or… whatever specific need you may have.

Anyway, here’s the python script.
Change the parameters in the INPUTS section and change the filename (the script uses a file called “for-test02.rcbox” but that can be any text you saved your file as.

import sys
from bs4 import BeautifulSoup
### INPUTS
overlap = 2 # Percentage overlap
partsX = 4 # divide
partsY = 4 # divide
# Read XML file created by Reality Capture
rcboxFile = BeautifulSoup(open("for-test02.rcbox"), "xml")
whd = str(rcboxFile.widthHeightDepth)
whd = (whd[18:(len(whd)-19)])
whd = whd.split(' ')
originalSizeX = float(whd[0])
originalSizeY = float(whd[1])
originalSizeZ = float(whd[2])
center = str(rcboxFile.CentreEuclid)
center = (center[22:(len(center)-3)])
center = center.split(' ')
centerX = float(center[0])
centerY = float(center[1])
centerZ = float(center[2])
# Output base filename
outBaseFileName = "boundingBox"
newSizeX = originalSizeX / partsX
newSizeY = originalSizeY / partsY
offsetX = centerX - (originalSizeX / 2)
offsetY = centerY - (originalSizeY / 2)
for j in range(1, partsY + 1):
for i in range(1, partsX + 1):
#print ("Part x={}, y={}". format(i, j))
newCenterX = offsetX + ((i - 0.5) * newSizeX)
newCenterY = offsetY + ((j - 0.5) * newSizeY)
newOverlapSizeX = newSizeX * (1 + (overlap / 100))
newOverlapSizeY = newSizeY * (1 + (overlap / 100))
#print ("New Center x={}, y={}".format(newCenterX, newCenterY))
fileName = outBaseFileName + "_{}_{}.rcbox".format(i, j)
line1 = '<ReconstructionRegion globalCoordinateSystem="+proj=geocent +ellps=WGS84 +no_defs" globalCoordinateSystemName="local:1 - Euclidean"\n'
line2 = ' isGeoreferenced="0" isLatLon="0" yawPitchRoll="0 -0 -0">\n'
line3 = ' <widthHeightDepth>{} {} {}</widthHeightDepth>\n'.format(newOverlapSizeX,newOverlapSizeY, originalSizeZ)
line4 = ' <Header magic="5395016" version="2"/>\n'
line5 = ' <CentreEuclid centre="{} {} {}"/>\n'.format(newCenterX, newCenterY, centerZ)
line6 = ' <Residual R="1 0 0 0 1 0 0 0 1" t="0 0 0" s="1"/>\n'
line7 = '</ReconstructionRegion>\n'
fileContent = line1 + line2 + line3 + line4 + line5 + line6 + line7
fileHandle = open(fileName, 'w')
fileHandle.write(fileContent)
fileHandle.close

← Back to all posts