Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SurfaceMatchingDialog.rb #113

Merged
merged 3 commits into from May 17, 2023

Conversation

Ski90Moo
Copy link
Contributor

@Ski90Moo Ski90Moo commented Jan 5, 2023

Resolved an issue with the intersect dialog (divided faces were not getting properly written the drawing_interface and were not getting added as OS model surface objects). Also improved the surface matching algorithm. New method uses centroid of the polygon for matching instead of trying to match every single vertex.

Testing has been successful thus far, but it could benefit from additional testing.

Fixes #75

Resolved an issue with the intersect dialog (divided faces were not getting properly written the drawing_interface and were not getting added as OS model surface objects).  Also improved the surface matching algorithm.  New method uses centroid of the polygon for matching instead of trying to match every single vertex.

Testing has been successful thus far, but it could benefit from additional testing.
@macumber
Copy link
Collaborator

macumber commented Jan 6, 2023

Wow @Ski90Moo, thanks for wading in to the code here! I will take a look at this over the weekend.

edges = entity.entities.grep(Sketchup::Edge)
edges.each {|edge| edge.find_faces} #Heal empty loops (no face) after intersection, this may not be necessary?

#Ski90Moo:This will find faces with AttributeDictionaries copied from the base face (this is causing the faces to be added to the drawing_interface but a new model surface object is not created because all the copies point to an existing surface object.) Rough work around solution is to delete the dictionary, delete the sketchup entity, and redraw it. This prompts the downstream observer to create a new model surface object and add the sketchup entities to the drawing_interface. There is probably a more direct solution without having to delete and redraw, but I do not fully understand how the observer works.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the idea is basically to trick SketchUp into thinking the surfaces after intersection are new? I think you identified the root cause of the issue but I do wonder if there is a better solution. Do you have a test model you could upload that demonstrates the bad behavior? You can upload it to a comment here if you rename to have a *.txt extension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. Utlimately, we need to get the observer to recognize the new surfaces as actually new, unique entities such that is adds them to the drawing_interface register with unique drawing_interface ids and also creates the corresponding OpenStudio surface object. Here is the test osm file:
test.txt

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ski90Moo, I can reproduce the issue with this test model

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this @macumber.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this issue happen every time for you on this model @Ski90Moo? I am having trouble reproducing it tonight for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that makes sense. I am using 2021 (mainly because of the renaming spaces in inspector issue). I'll do some testing with 2022 and see if it is still an issue. Otherwise, I agree, the better matching should be the focus for now.

Copy link
Collaborator

@macumber macumber Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addition to checking the area before and after equals 3529.2888356448607, I started checking number of surfaces as well:

OpenStudio::Plugin.model_manager.model_interface.openstudio_model.getSurfaces.inject(0) {|sum, s| sum += 1 } returns 96 after intersection (in case of self intersecting polygon). It returns 97 for correct intersection. There are 62 surfaces to begin with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found another surface that can fail to get broken into multiple pieces, unfortunately this occurs in SketchUp 2023 as well.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another failed intersection

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you send me the test model?

new_faces = after_faces - before_faces #find the new faces (that just copied the attributes from the base face)
temp = [] #create array to temporarily store new_faces vertices
new_faces.each do |face|
face.delete_attribute('OpenStudio') #delete dictionary attributes from the copied face so it will not delete the OS model object when deleted
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this is that you lose all information associated with the OpenStudio object. Also what deletes the OpenStudio object so we don't create new ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the ModelManager tracks and deletes these. Are you getting some that are duplicated or left over?

I thought it would be a concern regarding the surface properties (ie. boundary conditions and sun/wind exposure) getting reset from the original undivided surface. However, I did some testing and remarkably the surface properties carry forward.

@macumber
Copy link
Collaborator

macumber commented Feb 12, 2023

@Ski90Moo I put together some reduced matching logic similar to yours but trying to cut down on false positives in this PR #115

I think the biggest problem I see is that sometimes the intersect method results in self intersecting polygons like this:
image

It will be some work, but I think we can detect and fix these self-intersecting polygons after the intersection. The biggest lift will be implementing a self-intersecting polygon algorithm like the one discussed here. Ruby implementation here.

@Ski90Moo
Copy link
Contributor Author

Ok, I'll have to spend some time reviewing this. I came across this same issue when researching the intersect solution and stumbled on this thread. It seems that SketchUp has improved their intersecting since then, so I am not sure why we are still getting this issue. I put in the .find_faces method to try to resolve some of these empty and self intersecting polygon issues

@Ski90Moo Ski90Moo mentioned this pull request Feb 15, 2023
@Ski90Moo
Copy link
Contributor Author

Ski90Moo commented Apr 13, 2023 via email

@macumber macumber closed this Apr 14, 2023
@macumber macumber reopened this Apr 14, 2023
@macumber
Copy link
Collaborator

Sent them by email

Added beta testing option for intersections and surface matching.
Added beta testing options for intersect and surface matching.
@Ski90Moo
Copy link
Contributor Author

@macumber I added an option for beta testing the intersect and surface matching and retained the original methods on the latest changes...sorry, I have no idea what I am doing with Github, can you see the changes I made?

@macumber
Copy link
Collaborator

macumber commented May 1, 2023

Hey @Ski90Moo, yeah I can see your changes. I think adding a beta button is good balance. I closed #115. I'll test this out and merge for the next release (probably sometime in June). We'll give you credit in the release notes, thanks!

@Ski90Moo
Copy link
Contributor Author

Ski90Moo commented May 1, 2023

Thank you Dan

@macumber macumber mentioned this pull request May 2, 2023
@macumber
Copy link
Collaborator

macumber commented May 2, 2023

@Ski90Moo I moved this to #118 and reorganized the beta code all into one block. I also added a Contributor License Agreement (CLA) action. It requires you to "sign" the CLA before we can merge a PR with your changes on it. You can do this by adding a comment on my PR with the text "I have read the CLA Document and I hereby sign the CLA"

@macumber macumber merged commit 9044a29 into openstudiocoalition:develop May 17, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Intersect and Surface Matching
2 participants