How to edit points after loading them from file?

What happens is I set all my points, process wrapping, then I need to go back and add more points to fix up problems with the wrap. I know how to save points and load points, but what I need to do is be able to load points then add more points to that set. When I use loadPoints it loads from the file then goes straight to the next step. It doesn’t let me edit or add points. Is there a way I can do this? I don’t want to add 40 points all over again every time I need to tweak the wrapping.

Hello ozRocker!

If you want to add points to previously created set you can load them from file and then run dialog http://www.russian3dscanner.com/docs/WrapX/wrapDialogs.html#wrap.selectPoints. After the editing will be done this dialog will produce a new set of selected points, just give this set a new name. I suppose that you was using “Simple Wrapping Demo” which uses the same names and modified it to save edited pointsScan and pointsBasemesh to a file. So I slightly modified this example to show what I mean:


import wrap

print "Loading models..."
scan = wrap.Geom(wrap.demoModelsPath + "/AlexNeutral_3DHumanity.obj",scaleFactor = 1000)
scan.wireframe = False
scan.texture = wrap.Image(wrap.demoModelsPath + "/AlexNeutral_3DHumanity.jpg")

basemesh = wrap.Geom(wrap.demoModelsPath + "/HeadPolygroups_MakeHuman.obj")
wrap.fitToView()
print "OK"

# 1. Rigid Alignment
print "Rigid alignment..."

pointsScan = wrap.loadPoints("pointsScan.txt")
pointsBasemesh = wrap.loadPoints("pointsBasemesh.txt")

# START OF MODIFICATION
# Original version of script replaces previusly loaded pointsScan and pointsBasemesh with result of wrap.selectPoints
# By giving new names for returned values you don't touch originals
(pointsScan2, pointsBasemesh2) = wrap.selectPoints(scan,basemesh,pointsLeft = pointsScan,pointsRight = pointsBasemesh)
rigidTransformation = wrap.rigidAlignment(basemesh,pointsBasemesh2,scan,pointsScan2)
# END OF MODIFICATION - pointsBasemesh and pointsScan are not touched


basemesh.transform(rigidTransformation)
basemesh.fitToView()
print "OK"

If you will experience troubles with this example you can show a sample of your code and I will modify it according to your needs.

Ivan

Awesome!! That works perfectly ;D Thanx mate!
I was altering the FitMarvelousAvatar python file so I could save the points.

hi, i dont understand this at all.

can you guys please help me?

this is what im using. its the simple wrapping preset but with deleted things that i dont need.

import wrap

1. Loading Basemesh

print “Loading basemesh…”
basemeshFileName = wrap.openFileDialog(“Select Basemesh”,filter = “OBJ-file (*.obj)”,dir = wrap.demoModelsPath)
basemesh = wrap.Geom(basemeshFileName)
print “OK”

2. Loading Scan

print “Loading scan…”
scanFileName = wrap.openFileDialog(“Select Scan”,filter = “OBJ-file (*.obj)”,dir = wrap.demoModelsPath)
scaleFactor = 1000
scan = wrap.Geom(scanFileName,scaleFactor = scaleFactor)
scan.wireframe = False
print “OK”

3. Rigid Alignment

print “Rigid alignment…”
(pointsScan, pointsBasemesh) = wrap.selectPoints(scan,basemesh)
rigidTransformation = wrap.rigidAlignment(basemesh,pointsBasemesh,scan,pointsScan,matchScale = True)
basemesh.transform(rigidTransformation)
basemesh.fitToView()
print “OK”

4. Non-rigid Registration

print “Non-rigid Registration…”
(controlPointsScan,controlPointsBasemesh) = wrap.selectPoints(scan,basemesh)
freePolygonsBasemesh = wrap.selectPolygons(basemesh)
basemesh = wrap.nonRigidRegistration(basemesh,scan,controlPointsBasemesh,controlPointsScan,freePolygonsBasemesh,minNodes = 15,initialRadiusMultiplier = 1.0,smoothnessFinal = 0.1,maxIterations = 20)
print “OK”

8. Saving Result

print “Saving result…”
fileName = wrap.saveFileDialog(“Save resulting model”,filter = “OBJ-file (.obj)")
basemesh.save(fileName,scaleFactor = 1.0 / scaleFactor)
if scan.texture is not None:
textureFileName = wrap.saveFileDialog(“Save resulting texture”,filter = "Image (
.jpg *.png *.bmp *.tga)”)
basemesh.texture.save(textureFileName)
print “OK”

how should i edit this? i want a universal script to be able to go back and edit non-rigid alignment points and do the wrapping again.
also it would be great to start wrapping from the default base mesh, not the wraped one because its usually messed up, thats why im want to go back and edit points but i dont want it to wrap the messed up basemesh.

can you please help me modify the script so it would work? i dont know shit about coding.

thank you

Please try this script. It does exactly what you want

import wrap

# 1. Loading Basemesh
print "Loading basemesh..."
basemeshFileName = wrap.openFileDialog("Select Basemesh",filter = "OBJ-file (*.obj)",dir = wrap.demoModelsPath)
basemesh = wrap.Geom(basemeshFileName)
print "OK"

# 2. Loading Scan
print "Loading scan..."
scanFileName = wrap.openFileDialog("Select Scan",filter = "OBJ-file (*.obj)",dir = wrap.demoModelsPath)
scaleFactor = 1000
scan = wrap.Geom(scanFileName,scaleFactor = scaleFactor)
scan.wireframe = False
print "OK"

# 3. Rigid Alignment
print "Rigid alignment..."
(pointsScan, pointsBasemesh) = wrap.selectPoints(scan,basemesh)
rigidTransformation = wrap.rigidAlignment(basemesh,pointsBasemesh,scan,pointsScan,matchScale = True)
basemesh.transform(rigidTransformation)
basemesh.fitToView()
print "OK"


controlPointsScan = []
controlPointsBasemesh = []
freePolygonsBasemesh = []
while True:
    # 4. Non-rigid Registration
    print "Non-rigid Registration..."
    (controlPointsScan,controlPointsBasemesh) = wrap.selectPoints(scan,basemesh,controlPointsScan,controlPointsBasemesh)
    freePolygonsBasemesh = wrap.selectPolygons(basemesh,freePolygonsBasemesh)
    basemeshWrapped = wrap.nonRigidRegistration(basemesh,scan,controlPointsBasemesh,controlPointsScan,freePolygonsBasemesh,minNodes = 15,initialRadiusMultiplier = 1.0,smoothnessFinal = 0.1,maxIterations = 20)
    basemesh.hide()
    print "OK"
    if wrap.customDialog('Do you want to adjust parameters and wrap again?',['Again','Continue']) == 'Continue':
        break

# 8. Saving Result
print "Saving result..."
fileName = wrap.saveFileDialog("Save resulting model",filter = "OBJ-file (*.obj)")
basemeshWrapped.save(fileName,scaleFactor = 1.0 / scaleFactor)
print "OK"

wow, youre a baller man. cant wait to try it. thank you… ill give feedback later.

thanks again.

edit: works great. thanks again

Python and coding are things I don’t know how to do. I purchased WrapX because I need what it does. Any help is greatly appreciated.

I read in this forum that you can save and load points with:

wrap.savePoints(points, filename)
wrap.loadPoints(fileName)

The above is for Rigid Alignment and Non-Rigid Registration points, I think. I don’t know what the code below is for.

wrap.savePolygons(polygons, filename)
wrap.loadPolygons(fileName)

I want to say/do in Python the following for both Rigid Alignment and Non-Rigid Registration, if it is possible:

Are there points to be loaded for the models?
If yes, load the saved points file now for the models.
(With the ability to edit the loaded points if necessary).
If no, select the points now.
Save a file of the selected, edited points.

Because I don’t understand coding I am having a difficult time even given the examples:
http://www.russian3dscanner.com/forum/index.php?topic=412.msg878;topicseen#msg878
http://www.russian3dscanner.com/forum/index.php?topic=410.0

I am trying variations of the following, but I also don’t know the proper where, whens or whys to put things, so the following is like a Frankenstein rehash done without the knowledge of the species:



if wrap.customDialog('Load Rigid Alignment points?',['Stop Script','Continue']) == 'Stop Script':
    raise Exception('Stopped')

print 'Load Avatar Rigid Alignment points...'
fileNameAvatarpoints = wrap.openFileDialog('Open Avatar Points file',filter = 'TXT-file (*.txt)')
(pointsAvatar) = wrap.loadPoints(fileNameAvatarpoints)

print 'Load Scan Rigid Alignment points...'
fileNameScanpoints = wrap.openFileDialog('Open Scan Points file',filter = 'TXT-file (*.txt)')
(pointsScan) = wrap.loadPoints(fileNameScanpoints)

pointsScan = []
pointsAvatar = []
rigidTransformation = []
while True:
    # 4. Rigid Alignment
    print "Rigid Alignment..."
    pointsScan, pointsAvatar = wrap.selectPoints(scan,avatar,pointsLeft = [], pointsRight = [])
    rigidTransformation = wrap.rigidAlignment(avatar,pointsAvatar,scan,pointsScan,matchScale = False)
    avatar.transform(rigidTransformation)
    avatar.fitToView()
    print "OK"
    if wrap.customDialog('Do you want to adjust parameters and align again?',['Again','Continue']) == 'Continue':
        break

print 'Rigid Alignment...'
pointsScan, pointsAvatar = wrap.selectPoints(scan,avatar)
rigidTransformation = wrap.rigidAlignment(avatar,pointsAvatar,scan,pointsScan,matchScale = False)
avatar.transform(rigidTransformation)
avatar.fitToView()

if wrap.customDialog('Save Rigid Alignment points?',['Stop Script','Continue']) == 'Stop Script':
    raise Exception('Stopped')

print 'Saving Avatar Rigid Alignment points'
fileNameAvatarpoints2 = wrap.saveFileDialog('Save Avatar Rigid Alignment points', filter = "TXT-file (*.txt)")
(pointsAvatar) = wrap.savePoints(fileNameAvatarpoints2)

print 'Saving Scan Rigid Alignment points'
fileNameScanpoints2 = wrap.saveFileDialog('Save Scan Rigid Alignment points', filter = "TXT-file (*.txt)")
(pointsScan) = wrap.savePoints(fileNameScanpoints2)

if wrap.customDialog('Continue with non-rigid registration?',['Stop Script','Continue']) == 'Stop Script':
    raise Exception('Stopped')

if wrap.customDialog('Load non-rigid registration points?',['Stop Script','Continue']) == 'Stop Script':
    raise Exception('Stopped')

print 'Load Avatar Non-Rigid Registration points...'
fileNameAvatarControlpoints = wrap.openFileDialog('Open Avatar Registration Points file',filter = 'TXT-file (*.txt)')
(controlPointsAvatar) = wrap.loadPoints(fileNameAvatarControlpoints)

print 'Load Scan Non-Rigid Registration points...'
fileNameScanControlpoints = wrap.openFileDialog('Open Scan Registration Points file',filter = 'TXT-file (*.txt)')
(controlPointsScan) = wrap.loadPoints(fileNameScanControlpoints)

controlPointsScan = []
controlPointsAvatar = []
freePolygonsAvatar = []
while True:
    # 4. Non-rigid Registration
    print "Non-rigid Registration..."
    (controlPointsScan,controlPointsAvatar) = wrap.selectPoints(scan,avatar,controlPointsScan,controlPointsAvatar)
    freePolygonsAvatar = wrap.selectPolygons(avatar,freePolygonsAvatar)
    avatarWrapped = wrap.nonRigidRegistration(avatar,scan,controlPointsAvatar,controlPointsScan,freePolygonsAvatar,minNodes = 15,initialRadiusMultiplier = 1.0,smoothnessFinal = 0.1,maxIterations = 20)
    avatar.hide()
    print "OK"
    if wrap.customDialog('Do you want to adjust parameters and wrap again?',['Again','Continue']) == 'Continue':
        break

if wrap.customDialog('Save Non-Rigid Registration points?',['Stop Script','Continue']) == 'Stop Script':
    raise Exception('Stopped')

print 'Saving Avatar Rigid Alignment points'
fileNameAvatarControlpoints2 = wrap.saveFileDialog('Save Avatar Rigid Alignment points', filter = "TXT-file (*.txt)")
(controlPointsAvatar) = wrap.savePoints(fileNameAvatarControlpoints2)

print 'Saving Scan Rigid Alignment points'
fileNameScanpoints2 = wrap.saveFileDialog('Save Scan Rigid Alignment points', filter = "TXT-file (*.txt)")
(controlPointsScan) = wrap.savePoints(fileNameScanControlpoints2)

print 'Non-Rigid Registration...'
controlPointsScan,controlPointsAvatar = wrap.selectPoints(scan,avatar)
freePolygonsAvatar = wrap.selectPolygons(avatar)
initialRadiusMultiplier = 2.0
smoothnessFinal = 0.2
avatarWrapped = wrap.nonRigidRegistration(avatar,scan,controlPointsAvatar,controlPointsScan,freePolygonsAvatar,minNodes = 50,initialRadiusMultiplier = initialRadiusMultiplier,smoothnessFinal = smoothnessFinal,maxIterations = 20)
avatar.hide()

if wrap.customDialog('Continue with saving?',['Stop Script','Continue']) == 'Stop Script':
    raise Exception('Stopped')

print 'Saving Wrapped Avatar Model'
fileNameToSave = wrap.saveFileDialog('Save Wrapped Avatar Model', filter = "OBJ-file (*.obj)")
avatarWrapped.save(fileNameToSave,scaleFactor = 1.0 / scaleFactorScan)

print 'Wrapped avatar was saved to ' + fileNameToSave

Also, is there a way to maintain topology symmetry during the wrappig process?

I appreciate any help, advice and insights. Thank you.

This first part has given me some success (although points don’t seem to load), up to line 45 . The error I get is:

File “<wrap_console>”, line 45, in
TypeError: Argument pointsFloating must be a sequence, not NoneType

Here is the code:


import wrap

print 'Loaing avatar model...'
fileNameAvatar = wrap.openFileDialog('Open Topology Model',filter = 'OBJ-file (*.obj)')
avatar = wrap.Geom(fileNameAvatar)

print 'Loading 3D-scan model...'
scaleFactorScan = 1.0
fileNameScan = wrap.openFileDialog('Open Scan Model',filter = 'OBJ-file (*.obj)')
scan = wrap.Geom(fileNameScan,scaleFactorScan)
scan.wireframe = False
fileNameScanTexture = wrap.openFileDialog('Open Scan\'s Texture', filter = 'Image (*.jpg *.png *.bmp *.tga)')
if fileNameScanTexture is not None:
    scan.texture = wrap.Image(fileNameScanTexture)

if wrap.customDialog('Continue with rigid alignment?',['Stop Script','Continue']) == 'Stop Script':
    raise Exception('Stopped')

pointsScan = []
pointsAvatar = []
rigidTransformation = []
while True:
    # 4. Rigid Alignment
    print "Rigid Alignment..."
    print 'Load Avatar Rigid Alignment points...'
    fileNameAvatarpoints = wrap.openFileDialog('Open Points file',filter = 'TXT-file (*.txt)')
    if fileNameAvatarpoints is not None:
        (pointsAvatar) = wrap.loadPoints(fileNameAvatarpoints)

    print 'Load Scan Rigid Alignment points...'
    fileNameScanpoints = wrap.openFileDialog('Open Points file',filter = 'TXT-file (*.txt)')
    if fileNameScanpoints is not None:
        (pointsScan) = wrap.loadPoints(fileNameScanpoints)
    
    pointsScan, pointsAvatar = wrap.selectPoints(scan,avatar,pointsLeft = [], pointsRight = [])
    
    print 'Saving Avatar Rigid Alignment points'
    fileNameAvatarpoints2 = wrap.saveFileDialog('Save Avatar Rigid Alignment points', filter = "TXT-file (*.txt)")
    (pointsAvatar) = wrap.savePoints(pointsAvatar,fileNameAvatarpoints2)

    print 'Saving Scan Rigid Alignment points'
    fileNameScanpoints2 = wrap.saveFileDialog('Save Scan Rigid Alignment points', filter = "TXT-file (*.txt)")
    (pointsScan) = wrap.savePoints(pointsScan,fileNameScanpoints2)
        
    rigidTransformation = wrap.rigidAlignment(avatar,pointsAvatar,scan,pointsScan,matchScale = False)
    avatar.transform(rigidTransformation)
    avatar.fitToView()
    print "OK"
    if wrap.customDialog('Do you want to adjust parameters and align again?',['Again','Continue']) == 'Continue':
        break

Line 45 reads:
rigidTransformation = wrap.rigidAlignment(avatar,pointsAvatar,scan,pointsScan,matchScale = False)

Not sure what the problem is.

Hello,
I have modified SimpleWrapping script. It saves control points and polygons to file and read them next time if the files exist.

For simplicity i assume that the template and the target are pre-aligned and shares the same scale.

A minimal example for polygons looks like this

fileName = 'D:/polygons.txt'
if os.path.isfile(fileName):
	polygons = wrap.loadPolygons(fileName)
polygons = wrap.selectPolygons(basemesh,polygons)
wrap.savePolygons(polygons,fileName)

Full script:
import wrap
import os.path

1. Loading Basemesh

print “Loading basemesh…”
basemeshFileName = wrap.openFileDialog(“Select Basemesh”,filter = “OBJ-file (*.obj)”,dir = wrap.demoModelsPath)
basemesh = wrap.Geom(basemeshFileName)
print “OK”

2. Loading Scan

print “Loading scan…”
scanFileName = wrap.openFileDialog(“Select Scan”,filter = “OBJ-file (*.obj)”,dir = wrap.demoModelsPath)
scan = wrap.Geom(scanFileName)
scan.wireframe = False
print “OK”

print “Loading texture…”
textureFileName = wrap.openFileDialog(“Select Scan's Texture”,filter = “Image (*.jpg *.png *.bmp *.tga)”,dir = wrap.demoModelsPath)
if textureFileName is not None:
scan.texture = wrap.Image(textureFileName)
scan.texture.show()
print “OK”
else:
print “No texture set”

3. Loading points and polygons if there are any

fileNamePointsScan = ‘D:/pointsScan.txt’
fileNamePointsBasemesh = ‘D:/pointsBasemesh.txt’
fileNamePolygonSelection = ‘D:/polygonSelection.txt’
controlPointsScan = ()
controlPointsBasemesh = ()
freePolygonsBasemesh = ()

if os.path.isfile(fileNamePointsBasemesh):
controlPointsBasemesh = wrap.loadPoints(fileNamePointsBasemesh)
if os.path.isfile(fileNamePointsScan):
controlPointsScan = wrap.loadPoints(fileNamePointsScan)
if os.path.isfile(fileNamePolygonSelection):
freePolygonsBasemesh = wrap.loadPolygons(fileNamePolygonSelection)

4. Non-rigid Registration

print “Non-rigid Registration…”
(controlPointsScan,controlPointsBasemesh) = wrap.selectPoints(scan,basemesh,controlPointsScan,controlPointsBasemesh)
if (controlPointsScan is not None):
wrap.savePoints(controlPointsScan,fileNamePointsScan)
if (controlPointsBasemesh is not None):
wrap.savePoints(controlPointsBasemesh,fileNamePointsBasemesh)
freePolygonsBasemesh = wrap.selectPolygons(basemesh,freePolygonsBasemesh)
if (freePolygonsBasemesh is not None):
wrap.savePolygons(freePolygonsBasemesh,fileNamePolygonSelection)
basemesh = wrap.nonRigidRegistration(basemesh,scan,controlPointsBasemesh,controlPointsScan,freePolygonsBasemesh,minNodes = 15,initialRadiusMultiplier = 1.0,smoothnessFinal = 0.1,maxIterations = 20)
print “OK”

5. Texture Transfer

print “Texture transfer…”
if scan.texture is not None:
basemesh.texture = wrap.transferTexture(scan,scan.texture,basemesh,(2048,2048),maxRelativeDist = 3)
basemesh.texture.extrapolate()
print “OK”

6. Saving Result

print “Saving result…”
fileName = wrap.saveFileDialog(“Save resulting model”,filter = “OBJ-file (.obj)")
basemesh.save(fileName,scaleFactor = 1.0)
if scan.texture is not None:
textureFileName = wrap.saveFileDialog(“Save resulting texture”,filter = "Image (
.jpg *.png *.bmp *.tga)”)
basemesh.texture.save(textureFileName)
print “OK”

Thank you. Sorry for delayed response, I had to step away for a bit.

I am learning a lot, though. I can use this tool much more effectively with the help given in this forum.

Are there tips for increasing the symmetry of wraps?

We have some ideas for pose normalization for full-body scans but unfortunately we don’t have it implemented yet.

Thank you for your reply. Both models are in the T pose. The issue I have may be that the “scan” model is not a scan and needs more subdivision (up to 200,000 polys)? The polygons of the face are getting warped and twisted in the wrap and are no longer symmetrical. Deleting half the mesh and mirroring won’t work because it will change the point order. The body wrap is fine.

Perhaps it has something to do with the inner mouth polygons of the Base Mesh and how I’ve isolated them?
Could be more control points need to be selected?
Could be that the heads are of different proportions than the bodies?